简体   繁体   中英

UITableView - "unable to dequeue a cell with identifier"

Where is the problem? I want to make a Table View and if u click on the cell it pops up another Table View What i must to do to fix that?

    - (UITableViewCell )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier2 = @"TableViewCell_2"; 
    TableViewController_2 *cell2 = (TableViewController_2)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier2 forIndexPath:indexPath]; 
    // Configure the cell... 
    int row = [indexPath row]; cell2.Spoj = _Spoj[row]; 
    return cell2; 
}

在您的tableView:cellForRowAtIndexPath:使用dequeueReusableCellWithIdentifier:而不是dequeueReusableCellWithIdentifier:forIndexPath:

For correct dequeueing there are these steps:

  • On the attributes inspector for the xib file, add the identifier. (not in the restorationID field)

  • In your viewDidLoad of the ViewController owning the tableview, register the nib

    [[self.tableview registerNib:[UINib nibWithName@"TheNibName" bundle:nil] withIdentifier:@"theSameIdentierInXib"];

  • call dequeue... in cellForRow (no need to cast cell type or check for nil from iOS 5+)

*note, registerClass can cause an assertion failure if used for cell xib.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM