【发布时间】:2015-11-03 18:37:59
【问题描述】:
我正在尝试在cellFotRowAtIndexPath 方法中自定义表格视图单元格,但未应用样式。
我是不是把代码放错地方了?
(void)viewDidLoad {
[super viewDidLoad];
self.buttonTitles = [[NSArray alloc] initWithObjects:@"1 Die", @"2 Dice", @"3 Dice", @"4 Dice", @"5 Dice", @"6 Dice", @"7 Dice", @"8 Dice", @"Roll with a Button", nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return buttonTitles.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"settingsCell" forIndexPath:indexPath];
// Configure the cell...
UIFont *cellFont = [UIFont fontWithName:@"Raleway-Thin" size:14];
NSString *titles = [self.buttonTitles objectAtIndex:indexPath.row];
cell.textLabel.text = titles;
cell.textLabel.font = cellFont;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.backgroundColor = [UIColor darkGrayColor];
return cell;
}
更新:
在视图调试器中有空单元格:
【问题讨论】:
-
视图控制器是 UITableViewController 还是 UIViewController 的子类?
-
@Avi,它是
UITableViewController的子类。 -
尝试将您的故事板上的单元格类型更改为“自定义”。不知道是否可以更改“基本”单元格类型,或其他预定义样式、属性。
-
这就是一个空的 tableView 的样子。在
tableView:numberOfRowsInSection:中设置断点,或者添加日志,查看返回的行数。
标签: objective-c uitableview custom-cell