0

ここに私のコード:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];

    }


    UIImage *myImage = [UIImage imageNamed:@"flower.png"];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];

    imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

    imageView.contentMode = UIViewContentModeScaleAspectFit;

    imageView.image = myImage;

    [cell.contentView addSubview:imageView];

    [imageView release];

    return cell;
}

commitEditingStyle 関数を実装した後、ナビゲーション バーの左側にある編集ボタンをクリックすると、画像が右に移動します。画像を各セルの中央に表示し、削除アイコンが表示されたときに移動しないようにします。どうやってやるの?ありがとう。

4

2 に答える 2

0

テーブルがグループ化されている場合は、これをコードに追加してみてください。
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { return NO; }

于 2012-12-03T18:21:36.237 に答える
0

画像を contentview に追加するのではなく、セルのビューに追加し、自動サイズ変更を none に設定します。

[imageView setAutoresizingMask:UIViewAutoresizingNone];
[cell addSubview:imageView];
于 2013-01-04T19:31:53.467 に答える