Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone NSNotification和异步下载帮助_Iphone_Objective C_Cocoa Touch_Nsxmlparser_Nsnotificationcenter - Fatal编程技术网

Iphone NSNotification和异步下载帮助

Iphone NSNotification和异步下载帮助,iphone,objective-c,cocoa-touch,nsxmlparser,nsnotificationcenter,Iphone,Objective C,Cocoa Touch,Nsxmlparser,Nsnotificationcenter,我正在从一个视图向另一个视图发送通知。我的问题是,我在CellForRowatingIndexPath方法中调用的视图中的通知仅在tableview滚动时发送。如何停止此操作并使其在图像下载后发送通知?这是我的密码: 谢谢 MKDev您的代码应该正常工作,当连接IDFinishLoading时,您调用NSNotificationCenter发送通知,在cellForRowAtIndexPath中没有post方法。据我所知,您的代码将触发整个表的重新加载。这将导致单元格刷新 因此,如果由于从完成消

我正在从一个视图向另一个视图发送通知。我的问题是,我在CellForRowatingIndexPath方法中调用的视图中的通知仅在tableview滚动时发送。如何停止此操作并使其在图像下载后发送通知?这是我的密码:

谢谢


MKDev

您的代码应该正常工作,当
连接IDFinishLoading
时,您调用
NSNotificationCenter
发送通知,在
cellForRowAtIndexPath
中没有post方法。据我所知,您的代码将触发整个表的重新加载。这将导致单元格刷新

因此,如果由于从完成消息触发重新加载而绘制单元格(图像现在已准备好显示),或者如果需要启动图像的异步下载,则需要在第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]];
   }
   ...
}

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

xcode只是一个IDE,与此问题无关。基本上,在connectDidFinishLoading加载时需要重新加载tableView,因此我尝试从asyncView向rootviewcontroller发送通知,以通知tableView重新加载。请告诉我,我如何做到这一点,而不必等到tableview已滚动?我的问题是,tableview没有得到重新加载时,图像已下载。tableView仅在滚动时重新加载。你知道如何解决这个问题吗?但是你确定“reloadTableView”在两者之间被调用了吗?我再次修改了代码-替换了重新加载的数据。在这个转换过程中,我在代码中使用切换到不同的单元格样式进行编辑。只有在滚动tableview时才会调用reloadTableView。这听起来很奇怪。打电话的人是谁?从代码中,只应在发送通知时调用它。也许您应该尝试重命名它,以防它与UITableView方法冲突?调用方位于CellForRowatineXpath方法中:[asyncImage loadImageFromURL:[NSURL URLWithString:pathImage]];