0

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;
}

这只是标题,我想放一个副标题。我将插入什么代码来实现字幕?

提前致谢

4

1 回答 1

1

要为您的单元格设置字幕,请使用以下detailtextLabel属性:

cell.detailTextLabel.text = @"My Subtitle";

UITableViewCellStyleSubtitle如果您希望字幕以正常方式显示(左对齐,在主文本标签下方,灰色字体稍小),您还应该确保您的单元格样式设置为

于 2012-08-13T21:32:54.357 回答