【发布时间】:2018-07-11 08:09:35
【问题描述】:
我跟随here添加UITableView标题,只是创建一个包含两个按钮的视图,但是当我运行应用程序时看不到两个按钮。
两个被覆盖的函数是:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 60.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *vw = [tableView dequeueReusableCellWithIdentifier:@"HeaderCell"];
return vw;
}
注意:目标ios:11.4,xcode是9.4.1,objective-c
========================================= ViewController.m的其余代码
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithStyle:UITableViewStylePlain];
if (self) {
for (int i = 0; i < 5; i++) {
[[BNRItemStore sharedStore] createItem];
}
}
return self;
}
- (IBAction)addNewItem:(id)sender
{
}
- (IBAction)toggleEditingMode:(id)sender
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
BNRItem *item = [BNRItemStore sharedStore].allItems[indexPath.row];
cell.textLabel.text = item.description;
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
//[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"HeaderCell"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [BNRItemStore sharedStore].allItems.count;
}
【问题讨论】:
-
您是否添加了自定义标题单元格类?我在这张图片中看不到任何文件名 HeaderCell。
-
有一个标识符为
HeaderCell的单元格。
标签: ios objective-c uitableview nstableviewheader