【发布时间】:2014-11-05 14:40:21
【问题描述】:
在我的tableView 的cellForRowAtIndexPath 方法中,我对第一行使用自定义单元格,对其他行使用常规UITableViewCell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"Cell";
if (indexPath.section == 0){
CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.titleLabel.text = @"Custom cell";
if (isLightTheme){
cell.titleLabel.textColor = [UIColor blackColor];
}
else{
cell.titleLabel.textColor = [UIColor whiteColor];
}
return cell;
}
else{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
cell.textLabel.text = @"Other cells";
if (isLightTheme){
cell.textLabel.textColor = [UIColor blackColor];
}
else{
cell.textLabel.textColor = [UIColor whiteColor];
}
return cell;
}
}
然后我调用一个方法来改变 isLightTheme 并重新加载数据:
-(void)changeTheme{
isLightTheme = false;
[self.myTable reloadData];
}
...但我的应用程序在此行崩溃:
cell.titleLabel.text = @"Custom cell";
出现错误:
'-[UITableViewCell titleLabel]: 无法识别的选择器发送到实例
我不明白发生了什么.. 当ViewController 第一次加载时,表格加载得非常好(isLightTheme 首先设置为true),但是当我更改isLightTheme 和reloadData 时崩溃。有人可以帮帮我吗?谢谢。
【问题讨论】:
标签: ios objective-c iphone uitableview