UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath: Exception

后端 未结 9 2071
悲&欢浪女
悲&欢浪女 2021-01-03 19:15

i actually dont see my error:

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


        
相关标签:
9条回答
  • 2021-01-03 19:57

    For me, it worked doing this:

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    

    UPDATE
    Place the above code in the following method:

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

    Just put it BEFORE editing the tableViewCell

    0 讨论(0)
  • 2021-01-03 19:58

    Look here: Loading TableViewCell from NIB

    This is Apple's document for this exact subject.

    //This is assuming you have tvCell in your .h file as a property and IBOutlet
    //like so:
    TableViewController.h
    @property(nonatomic,retain) IBOutlet UITableViewCell *tvCell;
    //Data Source Method...
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    
    if (cell == nil) {
    
        [[NSBundle mainBundle] loadNibNamed:@"TVCell" owner:self options:nil];
    
        cell = tvCell;
    
        self.tvCell = nil;
    

    use the loadNibNamed:owner:options method to load a cell in a nib. Set the cell instance to your nib object, then set the nib object to nil.

    Read the rest of the documentation that I've linked to know how to access subviews inside your cell.

    0 讨论(0)
  • 2021-01-03 20:01

    Make sure your reuse identifier in your NIB / Storyboard file for your prototype cell matches whatever you called CellIdentifier

     static NSString *CellIdentifier = @"Cell";
    
    0 讨论(0)
提交回复
热议问题