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

Don't add the image to the contentview but to the view of the cell and set the autoresizing to none.

[imageView setAutoresizingMask:UIViewAutoresizingNone];
[cell addSubview:imageView];
于 2013-01-04T19:31:53.467 回答
0

如果您的表是组样式的,请尝试将此添加到您的代码中:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { return NO; }

于 2012-12-03T18:21:36.237 回答