Val*_*din 3 objective-c uitableview uiactivityindicatorview ios6
我有显示一个恼人的问题UITableViewCell与UIActivityIndicatorView内部.我的tableView委托加载了部分数据.最后一个单元格始终指示加载过程,而未加载新部分.加载从tableView: willDisplayCell: forRowAtIndexPath:iOS 5(或iOS 5模拟器)中的.So 开始,它完美地运行,但在iOS 6(或iOS 6模拟器)中UIActivityIndicatorView仅首次显示.也许有些东西因iOS 6或iOS 6漏洞而被弃用?
这是我的dataSource:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
这是我的代表:
- (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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是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
Run Code Online (Sandbox Code Playgroud)
显然动画在某些时刻停止,我不明白为什么只在iOS 6中发生这种情况.所以我[_activityIndicatorView startAnimating];从init方法中删除并添加到layoutSubviews:
if(![_activityIndicatorView isAnimating])
[_activityIndicatorView startAnimating];
Run Code Online (Sandbox Code Playgroud)
我认为这是iOS 6的bug.
| 归档时间: |
|
| 查看次数: |
622 次 |
| 最近记录: |