【问题标题】:Application quits *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]应用程序退出 *** -[UITableView _configureCellForDisplay:forIndexPath:] 中的断言失败
【发布时间】:2016-02-06 03:05:29
【问题描述】:

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

*** -[UITableView _configureCellForDisplay:forIndexPath:] 中的断言失败,/BuildRoot/Library/Caches/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;
}

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    消息:

    未能从其数据源获取单元格

    表示您正在为您的 cellForRowAtIndexPath 方法返回 nil

    cellForRowAtIndexPath 方法的末尾将 return nil; 更改为 return cell;

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 2013-02-25
      • 2012-04-25
      相关资源
      最近更新 更多