我遇到了 cell.detailTextLabel.text = NULL 的问题,就像我之前的其他人一样。我已经阅读了这些线程,但无法解决我的问题。我正在使用 Storyboard,我的表格 View 使用动态原型(prototype)作为内容。我有一个原型(prototype)单元格,其标识符为“myCell”,并且我使用副标题作为样式。我之前已经这样做过几次,并且效果如预期,但这次出了问题。代码:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
MyClass *myClass = [self sectionNumber:indexPath.section rowNumber:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@", myClass.someProperty];
cell.detailTextLabel.text = @"Some text";
NSLog(@"%@", cell.detailTextLabel.text);
return cell;
}
我错过了什么? NSLog 打印出“NULL”。
汉克
最佳答案
试试这个方法:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * CellIdentifier = @"myCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
MyClass *myClass = [self sectionNumber:indexPath.section rowNumber:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@", myClass.someProperty];
cell.detailTextLabel.text = @"Some text";
NSLog(@"%@", cell.detailTextLabel.text);
return cell;
}
关于ios - cell.detailTextLabel.text 的问题(无重复),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23006549/