簡體   English   中英

由於UITableView dataSource必須在iOS 5.1 Simulator中從tableView:cellForRowAtIndexPath:返回單元格而導致應用程序崩潰

[英]app crash due to UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath: in iOS 5.1 Simulator

它可以在iOS 6模擬器上正常工作。 在iOS 5.1 Simulator上首次運行時,由於以下異常,它崩潰了。

*由於未捕獲的異常“ NSInternalInconsistencyException”而終止應用程序,原因:“ UITableView dataSource必須從tableView:cellForRowAtIndexPath返回一個單元格:”

這是我的代碼

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"Cell";

    cell = [theTableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            [[NSBundle mainBundle] loadNibNamed:@"listTableCell" owner:self options:NULL];
        }
        else{
            [[NSBundle mainBundle] loadNibNamed:@"listTableCell_iPad" owner:self         options:NULL];
        }
        cell = nibLoadCellForListDetails;
    }
    return cell;
}

在listTableCell.xib中,我將文件的所有者設置為我的表視圖控制器。 而且我在我的表視圖控制器中正確地將出口設置為nibLoadCellForListDetails。

似乎尚未實際創建任何單元格。 加入:

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

代替:

cell = [theTableView dequeueReusableCellWithIdentifier:cellIdentifier];

試試這樣

if (cell == nil) {
    NSArray *nib;
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

      nib =   [[NSBundle mainBundle] loadNibNamed:@"listTableCell" owner:self options:NULL];
    }
    else{
      nib =  [[NSBundle mainBundle] loadNibNamed:@"listTableCell_iPad" owner:self         options:NULL];
    }
    cell = [nib objectAtIndex:0];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM