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 中显示不正确 的相关文章

  • 如何“旋转”图层/视图(例如,就像在 enigmo 中一样)

    我知道如何根据触摸移动图层 但我也希望能够旋转图像 是否有任何示例代码显示如何执行此操作 或者有人可以给我一些建议吗 Thanks 最简单的方法是使用图层的变换属性 float angle M PI rotate 180 or 1 radi
  • iOS 中的 FacebookSDK 不显示关闭按钮且无法关闭

    您好 我已经为 iOS 6 应用程序集成了 Facebook SDK Facebook 身份验证和共享工作完美 但没有提供关闭 FB 对话框的规定 当FB对话框打开时 只有在身份验证成功后才会关闭 没有关闭或导航回来的规定 我如何制作关闭按
  • 从 NSString 获取子字符串,直到到达特定单词

    假设我有这个NSString Country Address Tel number 我该如何获取之前的子字符串Tel 国家地址 然后我该如何获取后面的子字符串Tel 数字 使用 NSScanner NSString string Count
  • 从 UIImagePickerControllerReferenceURL 加载 UIImage

    我正在使用 UIImagePickerController 来允许用户从图像库中选择图像 然后我想在 sqlite 数据库中启动该文件的位置 以便稍后可以参考它 我一直在谷歌上搜索如何做到这一点 但我的结果相当简短 我知道我可以通过调用委托
  • 一个 UITableView 中的两种不同的单元格类型

    大家好 我对如何在一个具有两个部分的 UITableView 中使用两种不同的单元格类型感到非常困惑 第一部分应返回一个大单元格 其中包含大量文本 另一部分应返回三个单元格 以导航到其他视图 我尝试过这样的 UITableViewCell
  • UIKIT_EXTERN_CLASS 和 UIKIT_EXTERN,这两个常量是什么?

    当我在文档中定义类时 我总是在 interface 之前看到这两件事 UIKIT EXTERN CLASS 和 UIKIT EXTERN 这些常量代表什么以及为什么 Apple 将其放在类之前 另一件事是 有文件 UIKitDefines
  • 错误:“消息回复时间太长”向设备手表套件 OS 2 发送消息

    从 Apple Watch 向设备发送消息时出现以下错误 错误域 WCErrorDomain代码 7012 消息回复时间太长 UserInfo NSLocalizedDescription 消息回复时间太长 NSLocalizedFailu
  • 如何检查 uiviewcontroller 是否存在于 uinavigationcontroller 堆栈中

    我有一个UINavigationController 我必须从 a 中弹出一个视图UINavigationController并将其替换为另一个视图 我们如何才能搜索到一个UIViewController对象并将其替换为另一个 当我打印时
  • 一种简单、干净的方式来切换/交换视图?

    我已经看了几个来源 但我仍然很困惑 我想创建一个具有多个视图的应用程序 只有标准视图 没有表视图或其他任何内容 我可以在其中单击每个视图上的按钮来访问其他视图 我已经看到了多种方法来做到这一点 但对我来说唯一有意义的方法是让应用程序委托负责
  • 在 xcode 4 中找不到 info.plist

    所以常规介绍 我是 Objective C 的新手 到处搜索但找不到 所以请帮忙 我想做的就是将我的应用程序设置为在后台获取位置更新 就是这样 我知道我应该在项目的 info plist 文件中将位置添加到 UIBackgroundMode
  • 我如何在 ANSI C 中实现类似于 Objective-C @encode() 编译器指令的东西?

    encode 指令返回一个 const char 它是传入的数据类型的各个元素的编码类型描述符 示例如下 struct test int ti char tc printf s encode struct test returns test
  • 为什么我的 x 轴在 iPhone 上不显示核心图?

    编辑 我认为我的问题更好地表述为 我怎样才能有一个不从零开始的 Y 轴 看起来 x 轴总是放置在 y 0 处 但我希望 x 轴位于 y 轴上的某个正数 这是一张包含更多常规数据的图表 我只是希望将 x 轴放置在绘图的最小 y 值 大约 77
  • 在 Swift 中使用 Obj-C 完成块

    在 Objective C 中 我有一个完成块类定义为 File h typedef void MYCompletionBlock BOOL success NSDictionary result NSError error 然后 在 Sw
  • 对 Objective-c 对象数组进行排序

    所以我有一个自定义课程Foo有许多成员 interface Foo NSObject NSString title BOOL taken NSDate dateCreated 在另一堂课上我有一个NSMutableArray包含这些对象的列
  • 如何在UIWindow中添加视图?

    我想添加一个视图UIWindow与以下代码 AppDelegate delegate AppDelegate UIApplication sharedApplication delegate UIWindow window delegate
  • iOS图片上的线测量

    我需要一些帮助来开始绘制末端带有圆圈的线条 并测量其长度 我能够划清界限 但无法让它移动 花了几个小时决定在 SO 上发布 因此 请参阅下图并指导我开始 任何使用 Objective C 的示例或教程都会有帮助 谢谢 这个想法看起来实现起来
  • ObjC 中的 self 是什么?我应该什么时候使用它?

    什么是self在 Objective C 中是什么意思 我应该何时何地使用它 是否类似于this在Java中 self指的是您正在使用的当前类的实例 是的 它类似于this在爪哇 如果您想对该类的当前实例执行操作 则可以使用它 例如 如果您
  • 如何在 Objective-C 标头中引用 Swift 枚举

    有没有办法从 Objective C 标头引用 Swift 枚举 如果你想在 Objective C 头中查看 Swift 类 你可以使用 objc class Foo 我没有看到枚举有任何类似的东西 你想做的事情叫做forward dec
  • NSDate 休息 5 小时

    我运行以下代码 NSDate now NSDate 日期 NSLog now now 并得到 2011 09 16 16 14 16 434 iSavemore 1229 7907 现在 2011 09 16 21 14 16 0000 如
  • 从堆栈弹出后重新出现 UITableViewCellSeperator 的问题

    我有一个将动态数据加载到表视图中的应用程序 当只有一项时 因此只有一个单元格 为了确保 UITableViewCellSeperator 没有显示这一项 我使用以下代码 CGFloat tableView UITableView table

随机推荐