ios - 未调用 cellForRowAtIndexPath,行数、节数和单元格高度返回正确

标签 ios objective-c uitableview

我尝试了很多东西,但它显示单元格

我已经添加委托(delegate)和数据源 tableview.dataSouce =self; tableview.Delegate = self; 行高的函数单元格 返回 44;

我不知道为什么表格 View 不显示

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    int count = (int)_dict_contact.count;
    return count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
        {
            NSArray *arr_email =[_dict_contact objectForKey:@"u_email"];
            int count = (int)arr_email.count;
            return count;
        }
            break;
        case 1:
        {
            NSArray *arr_phone =[_dict_contact objectForKey:@"u_phone"];
            return arr_phone.count;
        }
            break;
     }
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    MultipleContCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(!cell)
    {
        cell = [[MultipleContCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    switch (indexPath.section) {
        case 0:
        {
             NSArray *arr_email =[_dict_contact objectForKey:@"u_email"];
            cell.detail_lbl.text =[arr_email objectAtIndex:indexPath.row];
              return cell;
        }
            break;
        case 1:
        {
            NSArray *arr_phone =[_dict_contact objectForKey:@"u_phone"];
            cell.detail_lbl.text =[arr_phone objectAtIndex:indexPath.row];
              return cell;
        }
            break;
    }
       return cell;

}

但是在尝试了太多之后我的 cellForRowAtIndexPath 也没有被调用

最佳答案

您需要为 viewdidload 中的 MultipleContCell 调用 registerNib:forCellReuseIdentifierregisterClass:forCellReuseIdentifier。例如:

[_yourTableView registerNib:[UINib nibWithNibName:@"MultipleContCell"bundle:nil] forCellReuseIdentifier:@"MultipleContCell"];

关于ios - 未调用 cellForRowAtIndexPath,行数、节数和单元格高度返回正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43495627/

相关文章:

iphone - UITableView 自定义 header (如 FoodSpotting 应用程序)

ios - 使用 NSMutableArray 中对象的元素设置 cell.backgroundColor

swift - 如何向 UITableView 单元格添加视差效果

ios - 我应该快速使用 GCD 还是 NSOperationQueue

ios - 突出显示手指下的标签

ios - 从自定义单元格 UITableView 中删除行

ios - 使用 swift 更改 UIView 中的文本调整

ios - 无法在应用商店连接中的应用商店中添加新版本

ios - 是否有充分的理由反对让我的 TyphoonAssembly 成为单例?如果是这样,为什么?如果没有,是否有推荐的方法?

objective-c - Obj-C/Cocoa 接线接口(interface)对象