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 に答える