How can i use custom UITableViewCell and UITableView in same xib

后端 未结 3 680
既然无缘
既然无缘 2020-12-21 01:58

I want to use a custom UITableviewCell with UITableView in same xib without creating a UITableViewCell class?

As you can see bellow i set the identifier for UITableV

3条回答
  •  情深已故
    2020-12-21 02:35

    Add a UITableViewCell *customCell property to your view controller (for example, your file ShowUsers.h)...

    @property (nonatomic, strong) IBOutlet UITableViewCell *customCell;
    

    and connect it to the custom cell in your xib. Then use the following code in cellForRow (for example, your file ShowUsers.m) :

    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"NibName" owner:self options:nil];
        cell = self.customCell;
        self.customCell = nil;
    }
    

提交回复
热议问题