ios - UITableViewController 不显示自定义原型(prototype)单元格

标签 ios objective-c uitableview

我之前使用过 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是这样设置的: storyboard

虽然据我所知,我相信这应该可以工作,但我仍然无法让它工作,它一直在运行,在模拟器上看起来像下面这样:

emulator image

如有任何帮助,我们将不胜感激。 提前致谢!

最佳答案

您必须在 numberOfSectionsInTableView: 中返回一个非零数字:或者完全删除默认为 1 个部分的方法。

关于ios - UITableViewController 不显示自定义原型(prototype)单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25003116/

相关文章:

ios - 在 iPad 中隐藏 Admob 广告 View

iphone - -JSONValue 失败。错误跟踪为 : in Google currency converter in iPhone

ios - 在 UIView/UIViewController 关系中定义委托(delegate)

ios - 在 Swift 3 中将 .scheduledTimer 的变量返回到 TableView Cell

ios - UITableView 上的 JSON 数据

ios - 我的方法行不通

ios - 如何检查我的应用程序窗口中是否已存在 View ?

ios - 为 UITableView 指定 UITableViewRowAnimationNone 时发生行动画

ios - 排行榜显示随机类别

python - obj-C 与 python 中的 Unix 时间