每当我打电话调用reloadRowsAtIndexPaths删除的tableView contentOffset
reloadRowsAtIndexPaths
我的UITableView contentOffset被删除,是否有委托方法我可以用它来捕捉表视图更新和设置偏移再次使之保持在适当位置和不动画到视图中,或者干脆阻止它这样做?
我设置contentOffest在viewDidLoad中:
下面是一个例子用法:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[params valueForKey:@"index"], nil] withRowAnimation:UITableViewRowAnimationFade];
其去除contentOffset并动画眼帘,这是我不想要的。
更具体地说,当被重载的行位于indexPath.section 0和indexPath.row 0,即顶行时,似乎会发生这种情况。
更多信息
我一个异步请求后调用reloadRowsAtIndexPaths从服务器获取的图像。它基本上就像这样:
- 的cellForRowAtIndexPath被称为该检查磁盘上的拇指文件的存在,如果该文件不存在的占位符被加载在它的位置和异步请求在后台启动线程来获取图像。
- 当图像下载完成时,我会拨打
reloadRowsAtIndexPaths
以获取正确的单元格,以便正确的图像淡入以代替占位符图像。 - 细胞的量可以是不同的,因为该请求被称为内部的cellForRowAtIndexPath使得图像在加载作为细胞负载
的cellForRowAtIndexPath文件检查
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_small.gif",[[listItems objectAtIndex:indexPath.row] valueForKey:@"slug"]]];
if([[NSFileManager defaultManager] fileExistsAtPath:path]){
listCell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:path]];
} else {
listCell.imageView.image = [UIImage imageNamed:@"small_placeholder.gif"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[[[listItems objectAtIndex:indexPath.row] valueForKey:@"image"] valueForKey:@"small"],@"image",[NSString stringWithFormat:@"%@_small.gif",[[listItems objectAtIndex:indexPath.row] valueForKey:@"slug"]], @"name",indexPath,@"index",@"listFileComplete",@"notification",nil];
[NSThread detachNewThreadSelector:@selector(loadImages:) toTarget:self withObject:params];
[params release];
}
文件donwloaded通知:
-(void)fileComplete:(NSNotification *)notification {
[self performSelectorOnMainThread:@selector(reloadMainThread:) withObject:[notification userInfo] waitUntilDone:NO];
}
细胞重装(我已经硬编码了部分由于与陌生的部分数字的错误传递很少导致飞机坠毁:
-(void)reloadMainThread:(NSDictionary *)params {
NSIndexPath *index;
switch ([[params valueForKey:@"index"] section]) {
case 0:
index = [NSIndexPath indexPathForRow:[[params valueForKey:@"index"] row] inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[params valueForKey:@"index"], nil] withRowAnimation:UITableViewRowAnimationNone];
break;
default:
index = [NSIndexPath indexPathForRow:[[params valueForKey:@"index"] row] inSection:2];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:index,nil] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
感谢您的提示,我想我的问题是与reloadRowsAtIndexPaths和不beginUpdates因为问题仍然存在与开始/结束删除 – Alex 2011-05-24 14:50:26
编辑;我可能误解了其他代码的外观。 – 2011-05-24 14:57:24
我已经更新了我的问题,以便更深入地了解我的问题 – Alex 2011-05-24 15:11:49