刚接触 Xcode,我正在浏览一些苹果文档,它展示了如何设置文本和副标题。我对这些指南的问题是如何实现它们。
这就是我的数组当前的样子:
- (void)viewDidLoad {
[super viewDidLoad];
//Initialize the array.
listOfItems = [[NSMutableArray alloc] init];
//Add items
[listOfItems addObject:@"Iceland"];
[listOfItems addObject:@"Greenland"];
[listOfItems addObject:@"Switzerland"];
[listOfItems addObject:@"Norway"];
[listOfItems addObject:@"New Zealand"];
[listOfItems addObject:@"Greece"];
[listOfItems addObject:@"Rome"];
[listOfItems addObject:@"Ireland"];
}
这就是它返回数据的方式:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
// Set up the cell...
NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
这只是标题,我想添加一个副标题。 我需要插入什么代码来实现字幕?
提前致谢
最佳答案
要设置单元格的副标题,请使用 detailtextLabel
属性:
cell.detailTextLabel.text = @"My Subtitle";
如果您希望副标题以正常方式显示(左对齐,位于主文本标签下方,并采用稍小的灰色字体),您还应该确保单元格的样式设置为 UITableViewCellStyleSubtitle
/p>
关于ios - 将 TableView 数组拆分为标签和副标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11942366/