0
雖然我點擊第一個單元正常工作並正確隱藏。如何正確摺疊我的細胞?
而我單擊第二個單元格,後端單元已被合併,並顯示不正確。
這段代碼有什麼不對,請找出這段代碼有什麼問題。
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
#pragma mark table cell creating and loading the data
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *returncell;
AntzclubCell *cell;
WaterPurifierCell *cell1;
if(indexPath.row==0)
{
cell=[tableView dequeueReusableCellWithIdentifier:@"Antz"];
cell.img_antzClub.image=[UIImage imageNamed:@"car.png"];
[email protected]"CAR";
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor=[UIColor blackColor];
return cell;
}
else if (indexPath.row==1)
{
cell1=[tableView dequeueReusableCellWithIdentifier:@"WaterPurifier"];
cell1.img_waterPurifier.image=[UIImage imageNamed:@"water_purifier.png"];
[email protected]"WATERPURIFIER";
return cell1;
}
return returncell;
}
#pragma mark expanding height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row) {
case 0:
if(indexPath.row==selectindex)
{
return 350;
}
else
{
return 132;
}
break;
case 1:
if(indexPath.row==selectindex)
{
return 333;
}
else{
return 132;
}
default:
break;
}
return 0;
}
#pragma mark user selecting option
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%d %d",selectindex,indexPath.row);
if (indexPath.row==selectindex) {
NSLog(@"%d",selectindex);
selectindex=-1;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
if(selectindex !=-1)
{
NSIndexPath *prepath=[NSIndexPath indexPathForRow:selectindex inSection:0];
selectindex=indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:prepath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
selectindex=indexPath.row;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}