简体   繁体   English

iPhone SDK-异步下载方法

[英]iPhone SDK - Asynchronous Download Methods

In Erica Sadun's Download Helper, link here , I can put these methods into my classes: 在Erica Sadun的Download Helper中, 在此处链接 ,我可以将这些方法放入类中:

- (void) didReceiveData: (NSData *) theData;
- (void) didReceiveFilename: (NSString *) aName;
- (void) dataDownloadFailed: (NSString *) reason;
- (void) dataDownloadAtPercent: (NSNumber *) aPercent;

these methods obviously refer back to the "DownloadHelper.h" and "DownloadherHelper.m". 这些方法显然可以参考“ DownloadHelper.h”和“ DownloadherHelper.m”。 I want to know if I am able to access properties on the xib view such as textfields, uitableviews, uilabels ... etc in one of these methods. 我想知道是否可以使用以下方法之一访问xib视图上的属性,例如文本字段,uitableviews,uilabels等。 For example: 例如:

- (void) didReceiveFilename: (NSString *) aName {
    [label setText:@"hi"];
}

I have tried doing so, but the objects on the xib view won't update. 我尝试这样做,但是xib视图上的对象不会更新。 like the given example above. 就像上面的例子一样。 Is there any way to do this? 有什么办法吗?

Thanks, 谢谢,

Kevin 凯文

It should be possible to access/update the properties of any outlets that you have linked from your xib into your controller. 应该可以访问/更新从xib链接到控制器的所有插座的属性。 Have you verified via the debugger that the didReceiveFilename: message is being sent to your controller, and that label is non-nil when the setText: message is sent to it? 您是否已通过调试器验证了didReceiveFilename:消息正在发送至控制器,并且在向setText:消息发送该label时该label为非nil?

Edit : I communicated with the person that posted this question offline. 编辑 :我与离线发布此问题的人进行了沟通。 The problem was not related to the asynchronous downloads. 该问题与异步下载无关。 His code was attempting to notify the controller of the view that contained the table view that a download had started, but the message was sent to the wrong controller instance. 他的代码试图将包含表视图的视图通知控制器已开始下载,但消息已发送到错误的控制器实例。 Fixing this corrected the problem. 解决此问题已解决。

Changed from this: 从此更改:

   // code that switched to an existing DownloadViewController omitted...
   // the new download controller that is created here has no views seen by the user!
   DownloadViewController *download = [[DownloadViewController alloc] init];
   [download downloadstart];

To this: 对此:

   // code that switched to an existing DownloadViewController omitted...
   // use the existing DownloadViewController instead of creating a new one
   DownloadViewController *download = (DownloadViewController *)[[appDelegate.rootController viewControllers] objectAtIndex:1];
   [download downloadstart];

The downloadstart method is responsible for updating the table view in Kevin's code. downloadstart方法负责更新Kevin的代码中的表视图。

UI updates take place on the main thread, you should try UI更新在主线程上进行,您应该尝试

performSelectorOnMainThread:withObject:waitUntilDone: performSelectorOnMainThread:withObject:waitUntilDone:

[label performSelectorOnMainThread:@selector(setText:) 
           withObject:@"hi" waitUntilDone:NO];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM