我将通知从一个视图发送到另一种视图。我的问题是,在我在cellforrowatIndexpath方法中调用的视图中,只有在表格滚动时才会发送。下载图像后,如何停止此信息并使其发送通知?这是我的代码: https://gist.github.com/756302

谢谢

mkdev

有帮助吗?

解决方案

据我了解您的代码,该消息将触发整个表的重新加载。这应该导致细胞的刷新。

因此,您需要在第76行中签入第76行,是否正在绘制单元格,因为从完成消息中触发了重新加载(现在可以显示图像),或者是否需要启动图像的异步下载。

我想到的第一件事是在ReloAdtableView中设置属性:

- (void)reloadTableView
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"aaa"];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"name" object:nil];
    NSLog(@"removeobserver");
    loadImageFinished = YES;
    // if your table has several sections you'll need to adopt the section number 
    NSIndexSet *indices = [[NSIndexSet alloc] initWithIndex:0];
    [self.tableView reloadSections:indices withRowAnimation:UITableViewRowAnimationFade];
    [indices release];
}

然后添加

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   ...
   if (loadImageFinished) {
      ... 
   } else {
      [asyncImage loadImageFromURL:[NSURL URLWithString:pathImage]];
   }
   ...
}

请注意,该表被重新加载的原因可能还有其他原因 - 该视图可能已经消失或卸载,您可能不希望触发多次异步加载。

其他提示

当您的代码应该正确地工作时 connectionDidFinishLoading, ,你打电话给 NSNotificationCenter 要发送通知,没有邮政方法 cellForRowAtIndexPath

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top