简体   繁体   English

UITableViewController不显示自定义原型单元格

[英]UITableViewController not Displaying Custom Prototype Cells

I have used the UITableViewController before though most of it was with Nibs and not the Storyboard and i cant seem to get it to populate the look or the data. 我以前使用过UITableViewController,尽管其中大多数是与Nibs一起使用的,而不是与Storyboard一起使用的,我似乎无法获得它来填充外观或数据。

My UITableViewController is set up like the below: 我的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;
}

I have checked the array and all 4 objects are in there, so they should be able to populate the Row. 我已经检查了数组,所有4个对象都在其中,因此它们应该能够填充行。

My UITableViewCell class.h file is set up like so: 我的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

All of those Outlet's are connected to the Cell in the Storyboard and show the connection when using the assistant editor. 所有这些插座都连接到情节提要中的单元,并在使用助手编辑器时显示连接。 The cellIdentifier is correct and made sure i copy and pasted instead of trying to type it correctly each time. cellIdentifier是正确的,请确保我复制并粘贴,而不是每次都尝试正确键入。

The storyboard is set up like so: 故事板的设置如下: 故事板

Though to my knowledge i believe this should be working and i still cant get it to work, it keeps running to look like the below on the emulator: 尽管据我所知,我认为这应该可以工作,但仍然无法正常工作,但它仍在模拟器上运行,如下所示:

仿真器映像

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thank you in advance! 先感谢您!

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

You are returning zero for the number of sections in your table view, therefore it's not showing any sections. 您在表格视图中返回的节数为零,因此未显示任何节。 Use this: 用这个:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  // Return the number of sections.
  return 1;
}

I spent DAYS trying to find a solution to this. 我花了几天的时间试图找到解决方案。

I know I'm late to the game (and it certainly wasn't the reason why Keeasno's prototype cells weren't displaying) but if the answer above doesn't help the solution to my problem was that I was using the wrong "identifier" field in Interface Builder. 我知道我迟到了游戏(这当然不是Keeasno的原型单元无法显示的原因),但是如果上述答案对我的问题没有帮助,那就是我使用了错误的“标识符”接口构建器中的“”字段。 Make sure in the Interface builder that you are using the correct "identifier" field to provide your reusable identifier, see below: 确保在“接口”构建器中使用正确的“标识符”字段来提供可重复使用的标识符,请参见下文:

XCode Interface Builder Sceenshot XCode界面生成器Sceenshot

The Accessibility Identifier has nothing to do with prototype cells - it has to do with providing useful information for users requiring accessibility features (eg voice over assistance), see link below for more info: 可访问性标识符与原型单元无关,它与为需要可访问性功能的用户提供有用的信息(例如语音协助)有关,请参阅下面的链接以获取更多信息:

Making Your iOS App Accessible 使您的iOS应用可访问

In my logic, for responding to the tableView:cellForRowAtIndexPath: if dequeueReusableCellWithIdentifier returns a nil value, I create an instance myself. 按照我的逻辑,为了响应tableView:cellForRowAtIndexPath:如果dequeueReusableCellWithIdentifier返回nil值,我将自己创建一个实例。 The code looks like this: 代码如下:

 static NSString *cellIdentifier = @"CellIdentifier";

 MaterialTableViewCell *cell = [tableView
 dequeueReusableCellWithIdentifier: cellIdentifier];

 if (cell == nil)

          cell = [[MaterialTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:
 cellIdentifier];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM