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

Aja*_*mar 6 objective-c uitableview ios

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

我写了这段代码,但我得到了一个例外.

-[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'
Run Code Online (Sandbox Code Playgroud)

这是我的加载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;
Run Code Online (Sandbox Code Playgroud)

rck*_*nes 14

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