应用程序退出***断言失败 - [UITableView _configureCellForDisplay:forIndexPath:]

Nei*_*Nie 0 objective-c uitableview ios

这是我的代码UITableView.每当我加载视图时,我都会收到以下错误:

***断言失败 - [UITableView _configureCellForDisplay:forIndexPath:],/ BuildRoot/Library/Cache/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962 UITableView(; layer =; contentOffset :{0,0}; contentSize:{343,190}>)无法从其dataSource()获取单元格

创建表的方法是相同的.我一直在使用tableviews很长一段时间.但是,我无法弄清楚这是错的.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
            return 70;
            break;
        case 1:
            return 50;
            break;
        case 3:
            return 50;
            break;
        default:
            return 70;
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *Id = @"CellID2";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Id forIndexPath:indexPath];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Id];
    }

    UILabel *object = (UILabel *)[cell.contentView viewWithTag:1];
    UILabel *discription = (UILabel *)[cell.contentView viewWithTag:2];
    object.text = [array objectAtIndex:indexPath.row];

    switch (indexPath.row) {
        case 0:
            discription.text = self.Location;
            break;
        case 1:
            discription.text = self.LocationType;
            break;
        case 3:
            discription.text = self.rating;
            break;
        default:
            break;
    }

    return nil;
}
Run Code Online (Sandbox Code Playgroud)

rma*_*ddy 5

消息:

无法从其dataSource获取单元格

意味着你要返回nil你的cellForRowAtIndexPath方法.

切换return nil;到方法return cell;的最后cellForRowAtIndexPath.