我在显示时遇到一个烦人的问题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(使用前将#替换为@)