相关疑难解决方法(0)

调用reloadRowsAtIndexPaths会删除tableView contentOffset

每当我打电话

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.它基本上是这样的:

  • 调用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];

    }
Run Code Online (Sandbox Code Playgroud)

文件下载通知:

-(void)fileComplete:(NSNotification *)notification { …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview

9
推荐指数
1
解决办法
9023
查看次数

标签 统计

iphone ×1

objective-c ×1

uitableview ×1