每当我打电话
reloadRowsAtIndexPaths
Run Code Online (Sandbox Code Playgroud)
我的UITableView contentOffset被删除了,是否有一个委托方法我可以用来捕获表视图更新并再次设置Offset以使其保持原位并且不会动画到视图中,或者只是阻止它执行此操作?
我在viewDidLoad中设置contentOffest:
self.tableView.contentOffset = CGPointMake(0, 43);
Run Code Online (Sandbox Code Playgroud)
以下是一个示例用法:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[params valueForKey:@"index"], nil] withRowAnimation:UITableViewRowAnimationFade];
Run Code Online (Sandbox Code Playgroud)
这将删除contentOffset并将其动画到视图中,这是我不想要的.
更具体地说,当重新加载的行位于indexPath.section 0和indexPath.row 0(即顶行)时,会出现这种情况.
更多信息
我在从服务器获取图像的异步请求之后调用reloadRowsAtIndexPaths.它基本上是这样的:
reloadRowsAtIndexPaths正确的单元格,以便正确的图像淡入而不是占位符图像.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];
}
Run Code Online (Sandbox Code Playgroud)
文件下载通知:
-(void)fileComplete:(NSNotification *)notification { …Run Code Online (Sandbox Code Playgroud)