【问题标题】:Using Multiple UITableViewCells for one tableView对一个 tableView 使用多个 UITableViewCells
【发布时间】:2016-07-14 02:52:23
【问题描述】:

我不确定在使用多个自定义单元格视图时是否以正确的方式设置 UITableView。我似乎有我的表工作但是,我认为单元格的重用使您在加载视图后看到的第一个单元格与第一个单元格的大小相同,这应该是唯一一个大小加倍的单元格。一旦我滚动通过它们并备份它们,它们就会变成为它们设置的大小。

有正确的方法吗?我已经查看了其他表格并尝试了他们的方法,但这是我已经让它与那个缺陷一起工作的封闭式。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifier1 = @"profileCell";
    static NSString *CellIdentifier2 = @"profileCells";

    if (indexPath.section == 0) {
        PFProfileTableCellView * cell = (PFProfileTableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

        //only one row in this section
        return cell;

    } else{
        PFWallPostTableViewCell * cell = (PFWallPostTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];


        return cell;
    }
}

【问题讨论】:

    标签: ios objective-c uitableview storyboard


    【解决方案1】:

    使用此 UITableView 委托方法 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 并根据您的 tableview 的部分返回行高,如下例所示

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        if (indexPath.section == 0) {
            return 100.0;
        }
        return 50.0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-18
      • 1970-01-01
      • 2016-04-12
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 2015-06-22
      • 2020-06-27
      相关资源
      最近更新 更多