How do you load custom UITableViewCells from Xib files?

前端 未结 23 1972
抹茶落季
抹茶落季 2020-11-22 11:11

The question is simple: How do you load custom UITableViewCell from Xib files? Doing so allows you to use Interface Builder to design your cells. The answer app

23条回答
  •  孤城傲影
    2020-11-22 11:17

     NSString *CellIdentifier = [NSString stringWithFormat:@"cell %ld %ld",(long)indexPath.row,(long)indexPath.section];
    
    
        NewsFeedCell *cell = (NewsFeedCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell=nil;
    
        if (cell == nil)
        {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"NewsFeedCell" owner:nil options:nil];
    
            for(id currentObject in topLevelObjects)
            {
                if([currentObject isKindOfClass:[NewsFeedCell class]])
                {
                    cell = (NewsFeedCell *)currentObject;
                    break;
                }
            }
    }
    return cell;
    

提交回复
热议问题