Xcode tableview字幕

Mik*_* V. 1 xcode cell subtitle tableview

我一直在寻找帮助,但没有运气:(

我想在TableViewCells中设置字幕.每个单元格中的字幕不能相同.我一直在写一些代码:

- (void)viewDidLoad
{
[super viewDidLoad];
 tableData = [[NSArray alloc] initWithObjects:@"cell 1", @"cell 2", nil];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
return [tableData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath        *)indexPath 
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (cell == nil)
{ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle      reuseIdentifier:@"MyCell"];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row]; 

cell.detailTextLabel.text = @"Subtitle 1", @"Subtitle 2", nil;

return cell;
}
Run Code Online (Sandbox Code Playgroud)

问题在于 cell.detailTextLabel.text = @"Subtitle 1", @"Subtitle 2", nil;

有人知道如何在每个单元格中设置不同的字幕吗?

祝好运!:)

All*_*ian 6

与设置单元格标题的方式完全相同.您可以拥有另一个包含字幕的数组,并按如下方式获取:

- (void)viewDidLoad
{
    [super viewDidLoad];
    tableData = [[NSArray alloc] initWithObjects:@"cell 1", @"cell 2", nil];
    // Assuming that you have declared another property named 'tableSubtitles'
    tableSubtitles = [[NSArray alloc] initWithObjects:@"sub1", @"sub2", nil];
}
Run Code Online (Sandbox Code Playgroud)

然后在你的tableView:cellForRowAtIndexPath:方法中:

cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [tableSubtitles objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)