UITableViewCell 与 UIImageView 丢失动画(iOS 5 bug?)

发布于 2024-12-10 09:54:36 字数 3601 浏览 0 评论 0 原文

到目前为止,这对我来说效果很好 - 但在 iOS 5 中,当我在分组表格视图上的常规 UITableViewCell 上有一个 imageView ,并将表格从编辑设置为不编辑时,动画会丢失,文本和图像视图会对齐回到原位而不是滑动。我没有重新加载任何东西 - 在我想到简单地注释掉我所说的那一行之前,我将代码精简到几乎没有任何内容来解决这个问题

cell.imageView.image = [UIImage imageNamed:@"image.png"];

,然后一切正常。这是 iOS 5 中的一个错误吗?

编辑:到目前为止,我认为这是交付的 tableview 单元格的 UIImageView 的问题。对于自定义单元格和没有 imageView 的 UITableViewCell 来说,设置不编辑动画似乎是可以的。我很想找到一种方法来解决这个问题,这会让事情看起来不专业。

下面是我所说的分组表格视图部分的代码,这是 cellforrowatindexPath 的一部分:

static NSString *CellIdentifier = @"ItemDetailDefaultCell";
            UITableViewCell *cell = (UITableViewCell *)[tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
                cell.backgroundColor = [[UIApplication sharedDelegate] defaultCellBackgroundColor];

                cell.textLabel.backgroundColor = [UIColor clearColor];
                cell.textLabel.shadowOffset = CGSizeMake(0.0, 1.0);

                cell.detailTextLabel.backgroundColor = [UIColor clearColor];

                cell.detailTextLabel.font = detailTextLabelFont;
                cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
                cell.detailTextLabel.minimumFontSize = DETAIL_TEXT_LABEL_MINIMUM_FONT_SIZE;

                cell.detailTextLabel.textColor = [[UIApplication sharedDelegate] defaultDetailTextColor];
                cell.detailTextLabel.shadowColor = [[UIApplication sharedDelegate] defaultDetailShadowColor];
                cell.detailTextLabel.shadowOffset = CGSizeMake(0.0, 1.0);
            }
            else {
                UIView* subview;
                while ((subview = [[[cell contentView] subviews] lastObject]) != nil)
                    [subview removeFromSuperview];
                cell.textLabel.text = nil;
                cell.detailTextLabel.text = nil;
            }
            cell.selectionStyle = [[UIApplication sharedDelegate] defaultCellSelectionStyle];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.accessoryView = nil;
            cell.editingAccessoryView = nil;

            cell.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            cell.contentMode = UIViewContentModeLeft;

            cell.textLabel.textColor = [[UIApplication sharedDelegate] defaultMainTextColor];
            cell.textLabel.shadowColor = [[UIApplication sharedDelegate] defaultMainShadowColor];
            cell.textLabel.font = textLabelFont;
            cell.textLabel.adjustsFontSizeToFitWidth = YES;
            cell.textLabel.minimumFontSize = TEXT_LABEL_MINIMUM_FONT_SIZE;

            [(UACellBackgroundView *)cell.backgroundView setHeader:NO];
            if (row < itemsCount) {
                [(UACellBackgroundView *)cell.backgroundView setPosition:UACellBackgroundViewPositionMiddle];
            }
            else {//row == items.count
                if (self.editing) {
                    [(UACellBackgroundView *)cell.backgroundView setPosition:UACellBackgroundViewPositionMiddle];
                }
                else {
                    [(UACellBackgroundView *)cell.backgroundView setPosition:UACellBackgroundViewPositionBottom];
                }
            }
            cell.textLabel.text = item.name;
            cell.imageView.image = [UIImage imageNamed:@"status1.png"];
return cell;

This worked fine for me up until now - but in iOS 5, when I have an imageView on a regular UITableViewCell on a grouped tableview, and set the table from editing to NOT editing, the animation is lost and the text and image view just snap back into place instead of sliding. I am not reloading anything - I stripped my code down to almost nothing to solve this before I thought of simply commenting out the line where I say

cell.imageView.image = [UIImage imageNamed:@"image.png"];

and then everything worked fine. Is this a bug in iOS 5?

EDIT: So far, I think this is a problem with the UIImageView for the delivered tableview cells. It seems like the set-not-editing animation, for custom cells and UITableViewCell WITHOUT imageView is okay. I'd love to find a way to get around this, it makes things look unprofessional.

Below is my code for the part of the grouped tableview I am speaking of, this is part of cellforrowatindexPath:

static NSString *CellIdentifier = @"ItemDetailDefaultCell";
            UITableViewCell *cell = (UITableViewCell *)[tableView1 dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
                cell.backgroundColor = [[UIApplication sharedDelegate] defaultCellBackgroundColor];

                cell.textLabel.backgroundColor = [UIColor clearColor];
                cell.textLabel.shadowOffset = CGSizeMake(0.0, 1.0);

                cell.detailTextLabel.backgroundColor = [UIColor clearColor];

                cell.detailTextLabel.font = detailTextLabelFont;
                cell.detailTextLabel.adjustsFontSizeToFitWidth = YES;
                cell.detailTextLabel.minimumFontSize = DETAIL_TEXT_LABEL_MINIMUM_FONT_SIZE;

                cell.detailTextLabel.textColor = [[UIApplication sharedDelegate] defaultDetailTextColor];
                cell.detailTextLabel.shadowColor = [[UIApplication sharedDelegate] defaultDetailShadowColor];
                cell.detailTextLabel.shadowOffset = CGSizeMake(0.0, 1.0);
            }
            else {
                UIView* subview;
                while ((subview = [[[cell contentView] subviews] lastObject]) != nil)
                    [subview removeFromSuperview];
                cell.textLabel.text = nil;
                cell.detailTextLabel.text = nil;
            }
            cell.selectionStyle = [[UIApplication sharedDelegate] defaultCellSelectionStyle];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.accessoryView = nil;
            cell.editingAccessoryView = nil;

            cell.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            cell.contentMode = UIViewContentModeLeft;

            cell.textLabel.textColor = [[UIApplication sharedDelegate] defaultMainTextColor];
            cell.textLabel.shadowColor = [[UIApplication sharedDelegate] defaultMainShadowColor];
            cell.textLabel.font = textLabelFont;
            cell.textLabel.adjustsFontSizeToFitWidth = YES;
            cell.textLabel.minimumFontSize = TEXT_LABEL_MINIMUM_FONT_SIZE;

            [(UACellBackgroundView *)cell.backgroundView setHeader:NO];
            if (row < itemsCount) {
                [(UACellBackgroundView *)cell.backgroundView setPosition:UACellBackgroundViewPositionMiddle];
            }
            else {//row == items.count
                if (self.editing) {
                    [(UACellBackgroundView *)cell.backgroundView setPosition:UACellBackgroundViewPositionMiddle];
                }
                else {
                    [(UACellBackgroundView *)cell.backgroundView setPosition:UACellBackgroundViewPositionBottom];
                }
            }
            cell.textLabel.text = item.name;
            cell.imageView.image = [UIImage imageNamed:@"status1.png"];
return cell;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱咩 2024-12-17 09:54:36

您是否使用此方法进入编辑模式

[myTable setEditing:NOanimated:YES];

此外,如果您重新加载数据,这也会取消动画。

Are you entering edit mode using this method

[myTable setEditing:NO animated:YES];

Also, if you are reloading the data, that will cancel the animation as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文