Ale*_*lex 9 iphone objective-c uitableview
每当我打电话
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 {
[self performSelectorOnMainThread:@selector(reloadMainThread:) withObject:[notification userInfo] waitUntilDone:NO];
}
Run Code Online (Sandbox Code Playgroud)
单元重新加载(我有硬编码的部分,因为奇怪的部分编号被传递的错误很少导致崩溃:
-(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;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:我原来的答案可能没有集中在核心问题上
您是否在调用之前更改行数reloadRows...?reloadRows...专门用于动画值更改,因此您的代码应如下所示:
UICell *cell = [self cellForRowAtIndexPath:indexPath];
cell.label.text = @"Something new";
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]];
Run Code Online (Sandbox Code Playgroud)
这或多或少是你的样子,但表格视图忘记了它在哪里?
之前的讨论
你不会打电话-beginUpdates并-endUpdates重新加载。您调用-beginUpdates并-endUpdates围绕您对支持数据的相关修改,在此期间您应该调用-insertRowsAtIndexPaths:withRowAnimation:及其亲属。如果调用更新例程,则无需调用重新加载例程。在更新过程中重新加载是未定义的行为。
有关何时使用 的详细信息,请参阅批量插入、删除和重新加载行和节-beginUpdates。
| 归档时间: |
|
| 查看次数: |
9023 次 |
| 最近记录: |