【问题标题】:How to expand my table view cell?如何扩展我的表格视图单元格?
【发布时间】: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


【解决方案1】:

根据您想要支持的 iOS 版本,答案可能会有所不同,但您似乎没有实现 heightForRowAtIndexPath:

【讨论】:

  • 我已经实现了索引路径处行的估计高度,如果我的代码中有任何问题,请提及。
  • 您需要实现 heightForRowAtIndexPath: 是的,您的代码是错误的,因为您没有实现它并且您没有表明您正在使用自调整大小的单元格。
  • 我实现了 heightForRowAtIndexPath 现在正在扩展,但其他一些单元格正在扩展,但标签已合并......
  • 所以现在我了解了我们可以在表格视图中实现的自定义单元的数量.....
猜你喜欢
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 2012-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多