TableViewCell 在 iOS 6 中显示不正确

2024-03-05

我在显示时遇到一个烦人的问题UITableViewCell with UIActivityIndicatorView里面。我的 tableView 委托加载部分数据。最后一个单元格始终指示加载过程,而新部分未加载。加载开始于tableView: willDisplayCell: forRowAtIndexPath:所以在iOS 5(或iOS 5模拟器)中它工作得很好,但在iOS 6(或iOS 6模拟器)中UIActivityIndicatorView仅第一次显示。也许自 iOS 6 以来某些内容已被弃用,或者是 iOS 6 的 bug?

这是我的数据源:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    UITableViewCell* cell = nil;
    if (_callback != nil && !_noMoreBooks && indexPath.row == [_books count])
    {
        cell = [tableView dequeueReusableCellWithIdentifier:LTTableViewLoadMoreCellIdentifier];
        if (cell == nil)
        {
            cell = [[[LTLoadMoreCell alloc] initWithStyle:UITableViewCellStyleDefault
                                          reuseIdentifier:LTTableViewLoadMoreCellIdentifier] autorelease];
            [(LTLoadMoreCell*)cell setRowTag:-1];
        }
    }
    else
    {
        cell = [tableView dequeueReusableCellWithIdentifier:LTTableViewCellIdentifier];
        if (cell == nil)
        {
            cell = [[[LTBookCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LTTableViewCellIdentifier] autorelease];
            cell.selectionStyle = UITableViewCellSelectionStyleGray;
            ((LTBookCell*)cell)._hidePrice = NO;
        }
    }
    return cell;
}

这是我的代表:

- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
    if ([LTTableViewLoadMoreCellIdentifier isEqualToString:[cell reuseIdentifier]]
        && [(LTLoadMoreCell*)cell rowTag] != indexPath.row)
    {
        [(LTLoadMoreCell*)cell setRowTag:indexPath.row];
        NSUInteger remain = LT_STORE_BOOK_LIST_LIMIT - rowsLoaded;
        NSUInteger by = remain < LT_STORE_BOOKS_LOAD_PORTION ? remain : LT_STORE_BOOKS_LOAD_PORTION;
        _currentError = _callback(_genres, rowsLoaded, by);
        if (_currentError == LTNoInternetError)
        {
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
        }
        else if (_currentError != LTErrorNone)
        {
            _noMoreBooks = YES;
        }
    }
    else if ([LTTableViewCellIdentifier isEqualToString:[cell reuseIdentifier]])
    {
        if ((indexPath.row == rowsLoaded-1) && _currentError == LTNoInternetError)
        {
            NSUInteger remain = LT_STORE_BOOK_LIST_LIMIT - rowsLoaded;
            NSUInteger by = remain < LT_STORE_BOOKS_LOAD_PORTION ? remain : LT_STORE_BOOKS_LOAD_PORTION;
            _currentError = _callback(_genres, rowsLoaded, by);
            if (_currentError == LTErrorNone)
                [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewScrollPositionBottom];
        }
        LTBook* rowBook = [_books extraObjectAtIndex:indexPath.row];
        if (rowBook != nil)
        {
            ((LTBookCell*)cell)._book = rowBook;
            ((LTBookCell*)cell).isOdd = (indexPath.row % 2);
        }
    }
}

这是 LoadMoreCell.m:

#import "LTLoadMoreCell.h"

@implementation LTLoadMoreCell

@synthesize rowTag;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self)
    {
        _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [_activityIndicatorView startAnimating];
        [[self contentView] addSubview:_activityIndicatorView];
        [self setUserInteractionEnabled:NO];
    }

    return self;
}

- (void)dealloc
{
    [_activityIndicatorView release];
    [super dealloc];
}

#pragma mark -
#pragma mark *** UITableViewCell methods ***
#pragma mark -

- (void)layoutSubviews
{
    [super layoutSubviews];
    [_activityIndicatorView setAutoresizingMask:UIViewAutoresizingNone];
    CGSize cellSize = [[self contentView] frame].size;
    [_activityIndicatorView setCenter:CGPointMake(cellSize.width / 2, cellSize.height / 2)];
}

@end

显然动画会在某个时刻停止,我不明白为什么这种情况只发生在 iOS 6 中。所以我删除了[_activityIndicatorView startAnimating];来自 init 方法并添加到layoutSubviews this:

if(![_activityIndicatorView isAnimating])
       [_activityIndicatorView startAnimating];

我认为这是 iOS 6 的错误。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TableViewCell 在 iOS 6 中显示不正确 的相关文章

  • 比较具有相同值但顺序不同的两个数组

    我有 2 个 nsarray 具有相同的值但顺序不同 NSArray array1 0 1 2 3 NSArray array2 2 3 1 0 我需要一种方法来确定两个数组是否具有不同顺序的相同值 Kind of BOOL isSameV
  • iOS UIView子类,将透明文本绘制到背景

    我想将文本绘制到 UIView 上的子类上 以便文本从形状中切出 并且视图后面的背景显示出来 就像在 OSX Mavericks 徽标中找到的那样here http www n3rdabl3 co uk wp content uploads
  • 图像高斯模糊 - iOS 8

    我有一个移动的背景图像 我想模糊它的底部 我would只用 Photoshop 就能做到 但由于图像会移动 效果不太好 这就是我的意思 看图片底部 基本上就像底座对 iPhone 的影响一样 我使用的是 iOS 8 但不是 Swift 我根
  • UITableViewCell 的 viewDidAppear

    我通常使用viewDidAppear方法在视图完成出现后在视图上执行一些 UI 操作 我在各种情况下使用了此方法 它非常有用 但是 我需要在视图上进行一些 UI 更改UITableViewCell当它完成出现后 SDK中是否有任何可用的方法
  • 从视频生成缩略图 - ios7

    我用这个作为参考 从视频 URL 或 iPhone SDK 中的数据获取缩略图 https stackoverflow com a 6027285 1145339 该方法使用 MPMoviePlayerController 类而不是 AVF
  • NSString keepCount 是 2147483647 [重复]

    这个问题在这里已经有答案了 可能的重复 NSString 保留计数 https stackoverflow com questions 1390334 nsstring retain count Objective C NSString 属
  • -all_load 其他链接器标志导致第 3 方框架中的重复符号错误

    我有一个用于内部应用程序的静态库 其中包含一些常见的实用程序代码 从以前的 SO 帖子中 我发现为了在运行时加载静态库中的类别 我需要包括 all load ObjC在 构建设置 中的 其他链接器标志 字段中 但是 对于我也在使用的闭源第三
  • 在完成块中保留循环

    在我的课堂上 我创建了这个方法 void refreshDatasourceWithSuccess CreateDataSourceSuccessBlock successBlock failure CreateDataSourceFail
  • iPhone - 创建自定义 UITableViewCell 顶部和底部边框

    我一直在到处寻找 但还没有找到我的答案 我使用 JSON 中的动态单元格填充 UITableView 并尝试隐藏任何额外的单元格 我关闭了IB中的分隔符 当然所有的单元格分隔符都消失了 如何在每个 tableviewcell 的底部和顶部添
  • 在 iOS 中从 ACAccountStore 获取 Facebook uid?

    您好 我想获取 Facebook 用户的 UIDAC帐户商店在 iOS 6 中 self accountStore ACAccountStore alloc init ACAccountType FBaccountType self acc
  • UITableView:显示 tableFooterView 时运行代码?

    我正在使用 UIView表页脚视图 http developer apple com library ios documentation uikit reference UITableView Class Reference Referen
  • 每 24 小时触发一次方法

    我正在尝试每天在给定时间触发一个方法 我尝试了一些方法 但我无法真正使其发挥作用 任何意见 将不胜感激 此外 如果无论应用程序是否打开它都会触发 那就更理想了 这可能吗 UI本地通知 http developer apple com lib
  • (Kiss)XML xpath 和默认命名空间

    我正在开发一个 iPhone 项目 需要解析一些 xml xml 可能包含也可能不包含默认名称空间 我需要知道如何解析 xml 以防它使用默认命名空间 由于我需要读取和写入 xml 因此我倾向于使用 KissXML 但我愿意接受建议 这是我
  • Objective-C NSString for 循环与characterAtIndex

    我试图逐个字符地循环遍历 NSString 但出现 EXC BAD ACCESS 错误 您知道如何正确执行此操作吗 我已经在谷歌上搜索了几个小时但无法弄清楚 这是我的代码 m self textLength self text length
  • Cocoa 应用程序菜单栏不可点击

    我正在我的可可应用程序中构建一个菜单栏 其中包含以下代码 implementation我的自定义应用程序CustomApplication void setUpMenuBar CustomApplication sharedApplicat
  • 如何在没有 SDK 的情况下在 Objective C 中为 S3 创建预签名 URL?

    我正在构建一个 mac 应用程序not使用 AWS iOS 开发工具包 我尝试构建的 GET 请求应遵循以下通用格式 Authorization AWS AWSAccessKeyId base64 hmac sha1 VERB n CONT
  • UIView animateWithDuration:delay: 工作很奇怪

    我在使用 iPhone 动画块时遇到了一个奇怪的问题 这段代码 UIView animateWithDuration 2 delay 0 options 0 animations void controller setBackgroundC
  • UIPickerView selectRow 未按预期工作

    我创建了一个UIPickerView它有两个组件 第一个组件 A 的行数固定为 13 另一个组件 B 的行数可变 具体取决于 A 中选择的行 加载时UIPickerView我调用以下命令 以便我可以在两个组件中默认选择 但是我遇到的问题是只
  • 如果我使用自定义 UITableViewCell,是否需要设置 heightForRowAtIndexPath?

    如果我使用自定义 UITableViewCell 是否需要设置 heightForRowAtIndexPath 在我的 NIB 中 我已经设置了单元高度 当我覆盖 heightForRowAtIndexPath 时 单元格的内容不会出现 即
  • Objective-C 中发送给对象的消息可以被监听或者打印出来吗? [复制]

    这个问题在这里已经有答案了 可能的重复 Objective C 中拦截方法调用 https stackoverflow com questions 1618474 intercept method call in objective c 如

随机推荐