2

UITableViewCell の幅を調整できるかどうかを知りたいです。その左側に画像を配置したいと思います (アドレス帳の連絡先ビューのように)。ここで、私が達成しようとしていることの正確な写真を提供する投稿を見つけました。また、この投稿に対する回答を確認したいと思います。

4

3 に答える 3

2

OS3.0 には、API にいくつかのスタイル オプションがあり、必要に応じて実行できます。

または、Interface Builder 内で完全にカスタムのテーブル ビュー セルを作成することもできます。たとえば、私のアプリの 1 つで、cellForRowAtIndexPath でこれを行います。

PlaceViewCell *cell = (PlaceViewCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [self createNewPlaceCellFromNib];
}

そして、これがNIBから掘り出す方法です

- (PlaceViewCell*) createNewPlaceCellFromNib {
    NSArray* nibContents = [[NSBundle mainBundle]
                            loadNibNamed:@"PlaceCell" owner:self options:nil];
    NSEnumerator *nibEnumerator = [nibContents objectEnumerator];
    PlaceViewCell* placeCell = nil;
    NSObject* nibItem = nil;
    while ( (nibItem = [nibEnumerator nextObject]) != nil) {
        if ( [nibItem isKindOfClass: [PlaceViewCell class]]) {
            placeCell = (PlaceViewCell*) nibItem;
            if ([placeCell.reuseIdentifier isEqualToString: @"Place" ]) {
                //NSLog(@"PlaceCell - we have a winner!");
                break; // we have a winner
            } else {
                placeCell = nil;
                NSLog(@"PlaceCell is nil!");
            }
        }
    }
    return placeCell;
}

その後、UITableViewCell サブクラスを Interface Builder で直接作成できます。

于 2009-06-25T11:37:37.143 に答える
0

IMO UITableViewCell の幅を変更することは許可されていませんが、幸いなことに変更する必要はありません。Apple は、セルの左端に 1 つの画像を表示できる 4 つのデフォルト スタイルを提供しています (別の場所に配置したい場合は、カスタム レイアウトを作成する必要があります)。

UITableViewCellStyleの 4 つのスタイルは次のとおりです。

  • UITableViewCellStyleDefault
  • UITableViewCellStyleSubtitle
  • UITableViewCellStyleValue1
  • UITableViewCellStyleValue2

画像を UITableViewCell に埋め込むには、Apples Developer Connection ネットワークの TableView Programming Guide を読む必要があります: Using Cell Objects in Predefined Styles

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSDictionary *item = (NSDictionary *)[self.content objectAtIndex:indexPath.row];
    cell.textLabel.text = [item objectForKey:@"mainTitleKey"];
    cell.detailTextLabel.text = [item objectForKey:@"secondaryTitleKey"];
    NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"imageKey"] ofType:@"png"];
    UIImage *theImage = [UIImage imageWithContentsOfFile:path];
    cell.imageView.image = theImage;
    return cell;
}
于 2009-06-25T15:00:12.973 に答える
0

セルの幅を変更する必要はありません。実際に必要なのは、セルの幅が異なるように見せることです (たとえば、表示されるサブビューの幅を変更することによって)。

残念ながら、リンクが機能しないため、これ以上具体的に説明することはできません.

プロトコルのtableView:indentationLevelForRowAtIndexPath:メソッドを調べることもできます。UITableViewDelegate

于 2012-03-23T19:20:03.837 に答える