2012-11-15 69 views
3

我在显示UITableViewCellUIActivityIndicatorView时遇到了一个烦人的问题。我的tableView委托加载部分数据。最后一个单元总是指示加载过程,而新部分未加载。加载在tableView: willDisplayCell: forRowAtIndexPath:开始。因此,在iOS 5(或iOS 5模拟器)中它可以很好地工作,但在iOS 6(或iOS 6模拟器)中UIActivityIndicatorView仅在第一次显示。也许有些东西因为iOS 6而被弃用,或者是iOS 6的bug?TableViewCell在iOS 6中显示不正确

这里是我的数据源:

- (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 

回答

5

显然动画某一时刻停止,我不明白为什么会这样,只有在iOS的6于是,我从init方法去除[_activityIndicatorView startAnimating];并添加到layoutSubviews此:

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

我认为这是iOS 6中的bug 。

+0

我在iOS 6发布后不久就遇到了同样的事情 - 我们在表格单元格中显示了一些活动指标,并使用IB'动画'复选框,然后根据需要显示/隐藏视图。在iOS6上,它们出现,但不动画。这种技术在表格单元之外的其他区域继续正常工作。看起来他们打断了我。 – antsyawn

+0

同样在这里,在iOS 5中可以正常工作,但在iOS 6中不能正常工作!谢谢瓦伦丁! – Groot

2

你调用[activyView startAnimating]在您单元的只有INIT方法..尝试调用它之前,你想它动画:: willDisplayCell甚至viewForCell

+0

你给了我很好的提示,我发现解决方案!谢谢! –

+0

:)那是什么? /你做了什么 - PLZ分享你的解决方案:) –

+0

看我的答案!对不起,我的英语:-) –