How do you load custom UITableViewCells from Xib files?

前端 未结 23 2137
抹茶落季
抹茶落季 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:18

    What I do for this is declare an IBOutlet UITableViewCell *cell in your controller class. Then invoke the NSBundle loadNibNamed class method, which will feed the UITableViewCell to the cell declared above.

    For the xib I will create an empty xib and add the UITableViewCell object in IB where it can be setup as needed. This view is then connected to the cell IBOutlet in the controller class.

    - (UITableViewCell *)tableView:(UITableView *)table
             cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"%@ loading RTEditableCell.xib", [self description] );
    
        static NSString *MyIdentifier = @"editableCellIdentifier";
        cell = [table dequeueReusableCellWithIdentifier:MyIdentifier];
    
        if(cell == nil) {
            [[NSBundle mainBundle] loadNibNamed:@"RTEditableCell"
                                          owner:self
                                        options:nil];
        }
    
        return cell;
    }
    

    NSBundle additions loadNibNamed (ADC login)

    cocoawithlove.com article I sourced the concept from (get the phone numbers sample app)

提交回复
热议问题