ios - 如何在 iphone 的 tableview 中为单元格加载 xib 文件

标签 ios objective-c uitableview

我看到网上有很多关于这个问题的资源。我必须为我的单元加载不同的 XIB (UIViewContoller) 文件。我在那里设计了我的单元格外观,我想将该设计加载到我的单元格中。

我写了这段代码,但出现异常。

-[UIView setTableViewStyle:]: unrecognized selector sent to instance 0x6040de0
2011-07-11 14:42:27.461 TableViewTest[2776:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setTableViewStyle:]: unrecognized selector sent to instance 0x6040de0'

这是我加载nib文件的代码

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 if (cell == nil) {
    // Load the top-level objects from the custom cell XIB.
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"loadXibfile" owner:self options:nil];
    // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
    cell = [topLevelObjects objectAtIndex:0];
}


return cell;

最佳答案

您应该在 XIB 文件中使用 UITableViewCell 而不是 UIView

关于ios - 如何在 iphone 的 tableview 中为单元格加载 xib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6648004/

相关文章:

ios - Objective -C 如何从 NSMutableArray 创建视频?

ios - [[NSRunLoop currentRunLoop] runMode :* beforeDate:*]; 中的 BAD EXC

ios - Apple Table View 多行文本应该像每一行的最后一行一样加尾

uitableview - 删除表格中单元格的最后一个分隔符

iphone - QuartzCore中的渐变效果

ios - View 在 iPhone X 横向模式下看起来不正确

objective-c - 将 NSPredicateEditor 绑定(bind)到共享用户默认 Controller

objective-c - 释放/访问不同类中同名的不同对象

启动屏幕后 iOS 应用程序崩溃

ios - 访问 heightForRowAtIndexPath 中的自定义单元格属性