我看到网上有很多关于这个问题的资源。我必须为我的单元加载不同的 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/