快速问题。我正在尝试在Prototype单元格中添加另一个单元格。我添加了行“cell.textLabel.text = person.firstname;”但是不要在细胞上得到任何东西。有人可以帮忙吗
由于
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Persons Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
Person *person = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *fullname = [NSString stringWithFormat:@"%@, %@", person.surname, person.firstname];
cell.textLabel.text = fullname;
cell.detailTextLabel.text = person.inEvent.name;
cell.textLabel.text = person.firstname;
return cell;
}
答案 0 :(得分:0)
“在Prototype单元格中添加另一个单元格”是什么意思? ?我认为,根据您的代码,您想要的是为您的代码添加另一个UILabel
。从默认UITableViewCell
开始,您只有两个,textLabel
和detailTextLabel
。如果你还想要一个,你必须自己创造。
请注意,您要设置两次相同的标签。
cell.textLabel.text = fullname; //setting first time
cell.detailTextLabel.text = person.inEvent.name;
cell.textLabel.text = person.firstname; //setting second time. This will set a new text to 'textLabel', losing its previous content (fullname)
您可以分配一个新的并在cellForRowAtIndexPath:
内添加单元格内容视图的子视图。但我真的建议创建一个UITableViewCell
的子类,使用Interface Builder根据需要定位标签,为它们创建IBOutlets
,并在cellForRowAtIndexPath:
中设置它的文本。