我之前使用过 UITableViewController,虽然其中大部分是使用 Nibs 而不是 Storyboard,但我似乎无法使用它来填充外观或数据。
我的 UITableViewController 设置如下:
@implementation BFTBackThreadTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_dummyUsers = [[NSArray alloc] initWithObjects:@"@JonathanB",@"@NickyV",@"@Dman",@"C-LO-P", nil];
NSLog(@"%lu", (unsigned long)[_dummyUsers count]);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_dummyUsers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BFTThreadTableViewCell *cell = (BFTThreadTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
// Configure the cell
cell.userLabel.text = [_dummyUsers objectAtIndex:[indexPath row]];
return cell;
}
我检查了数组,所有 4 个对象都在其中,因此它们应该能够填充行。
我的 UITableViewCell class.h 文件是这样设置的:
@interface BFTThreadTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *userLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeStamp;
@property (weak, nonatomic) IBOutlet UIButton *numberMessageThread;
@end
所有这些 Outlet 都连接到 Storyboard 中的 Cell,并在使用助理编辑器时显示连接。 cellIdentifier 是正确的,并确保我复制并粘贴,而不是每次都尝试正确键入它。
Storyboard是这样设置的:
虽然据我所知,我相信这应该可以工作,但我仍然无法让它工作,它一直在运行,在模拟器上看起来像下面这样:
如有任何帮助,我们将不胜感激。 提前致谢!
最佳答案
您必须在 numberOfSectionsInTableView: 中返回一个非零数字:或者完全删除默认为 1 个部分的方法。
关于ios - UITableViewController 不显示自定义原型(prototype)单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25003116/