iPhone SDK - 异步下载方法

发布于 2024-09-18 22:37:12 字数 730 浏览 6 评论 0原文

在 Erica Sadun 的下载助手中, 链接在这里,我可以将这些方法放入我的类中:

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

这些方法显然引用了“DownloadHelper.h”和“DownloadherHelper.m”。我想知道我是否能够通过这些方法之一访问 xib 视图上的属性,例如文本字段、uitableviews、uilabels ...等。例如:

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

我尝试这样做,但 xib 视图上的对象不会更新。就像上面给出的例子一样。有什么办法可以做到这一点吗?

谢谢,

凯文

In Erica Sadun's Download Helper, link here, I can put these methods into my classes:

- (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". 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. For example:

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

I have tried doing so, but the objects on the xib view won't update. like the given example above. Is there any way to do this?

Thanks,

Kevin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆兒滾 2024-09-25 22:37:12

应该可以访问/更新从 xib 链接到控制器的任何插座的属性。您是否通过调试器验证了 didReceiveFilename: 消息正在发送到您的控制器,并且当 setText:label 为非零消息是发送给它的吗?

编辑:我与离线发布此问题的人进行了沟通。该问题与异步下载无关。他的代码试图通知包含表视图的视图的控制器下载已开始,但消息被发送到错误的控制器实例。解决这个问题就解决了问题。

更改为:

   // 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];

改为:

   // 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];

downloadstart 方法负责更新 Kevin 代码中的表视图。

It should be possible to access/update the properties of any outlets that you have linked from your xib into your controller. 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?

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.

浅忆流年 2024-09-25 22:37:12

UI更新发生在主线程上,你应该尝试

performSelectorOnMainThread:withObject:waitUntilDone:

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

UI updates take place on the main thread, you should try

performSelectorOnMainThread:withObject:waitUntilDone:

[label performSelectorOnMainThread:@selector(setText:) 
           withObject:@"hi" waitUntilDone:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文