1
在我tableView
的cellForRowAtIndexPath
方法,我使用的第一排和自定義單元格定期UITableViewCell
對於其他行:的TableView崩潰的reloadData - 「無法識別的選擇發送到實例」
- (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]: unrecognized selector sent to instance
我不明白這是怎麼回事..表加載完美的罰款(isLightTheme
首先設置爲true
)當ViewController
首次加載,但是當我改變isLightTheme
和reloadData
它崩潰。有人能幫我嗎?謝謝。
謝謝,這工作:) – BadBoolean 2014-11-05 14:50:07
很高興幫助! UITableViews可能會令人沮喪,但你很快就會喜歡它們。 ;-) – 2014-11-05 14:55:55