【发布时间】:2015-07-21 04:47:27
【问题描述】:
使用此代码展开表格视图单元格,但它对我不起作用。我知道此代码中有一些错误帮助我找出来。
![selectindex = -1;
// Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return \[Arr_lbl count\];
}
#pragma mark table cell creating and loading the data
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AntzclubCell *cell=\[tableView dequeueReusableCellWithIdentifier:@"Antz"\];
cell.img_antzClub.image=\[UIImage imageNamed:\[Arr_img objectAtIndex:indexPath.row\]\];
cell.lbl_antzClub.text=\[Arr_lbl objectAtIndex:indexPath.row\];
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor=\[UIColor blackColor\];
return cell;
}
#pragma mark expanding height
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectindex==indexPath.row){
return 400;
}
else{
return 132;
}
}
#pragma mark user selecting option
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==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:UITableViewRowAnimationLeft\];
}
selectindex=indexPath.row;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
}]
这张图片是我的输出,当我单击它与其他未扩展数据合并的单元格时。
【问题讨论】:
-
每个单元格的高度不同??
-
是不同的高度,但现在我为每个单元格实现了相同的高度。
-
这样您就可以使用对您有帮助的外部 api 类。您可以在您的应用中使用外部 api 类或在您的应用中复制外部 api 代码。
-
你能把链接发给我吗....如果可以的话。
标签: ios objective-c uitableview uitouch