0

我正在尝试将我的应用程序更新到 iOS 7,但分配的东西刚刚消失或不再工作:S。

我无法解决这个问题,我不知道它为什么返回 NULL。

*** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'


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

static NSString *cellIdentifier = @"Cell";

static NSString *cellIdentifier2 = @"Cell2";


NSDictionary *naamInfo;

if (tableView == self.searchDisplayController.searchResultsTableView) {
    naamInfo = [self.filteredNameArray objectAtIndex:indexPath.row];
} else {
    naamInfo = [self.nameList objectAtIndex:indexPath.row];
}



UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if ([[naamInfo objectForKey:@"gender" ] isEqual: @"man"] ) {

        cell = [UITableViewCell configureFlatCellWithColor:[UIColor peterRiverColor] selectedColor:[UIColor cloudsColor] reuseIdentifier:cellIdentifier inTableView:tableView];

    }else if ([[naamInfo objectForKey:@"gender" ] isEqual: @"woman"]){
        cell = [UITableViewCell configureFlatCellWithColor:[UIColor colorWithRed:1 green:0.396 blue:0.604 alpha:1]  selectedColor:[UIColor cloudsColor] reuseIdentifier:cellIdentifier2 inTableView:tableView];

    }

NSLog(@"CELL %@",cell);

    cell.detailTextLabel.font = [UIFont boldFlatFontOfSize:14];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.cornerRadius = 8.f; 
    cell.separatorHeight = 1.f; 

cell.textLabel.font = [UIFont boldFlatFontOfSize:18];
cell.textLabel.text = [naamInfo objectForKey:@"name"];
cell.detailTextLabel.text = [naamInfo objectForKey:@"country"];

return cell;

}

日志返回 NULL,所以我明白为什么我会得到异常,但我不明白如何解决这个问题?

4

1 回答 1

2

试着把:

if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}

后:

UITableViewCell *cell = [tableView dequeue....
于 2013-10-02T19:31:18.710 回答