iPhone SDK - 异步下载方法
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该可以访问/更新从 xib 链接到控制器的任何插座的属性。您是否通过调试器验证了
didReceiveFilename:
消息正在发送到您的控制器,并且当setText:
时label
为非零消息是发送给它的吗?编辑:我与离线发布此问题的人进行了沟通。该问题与异步下载无关。他的代码试图通知包含表视图的视图的控制器下载已开始,但消息被发送到错误的控制器实例。解决这个问题就解决了问题。
更改为:
改为:
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 thatlabel
is non-nil when thesetText:
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:
To this:
The
downloadstart
method is responsible for updating the table view in Kevin's code.UI更新发生在主线程上,你应该尝试
performSelectorOnMainThread:withObject:waitUntilDone:
UI updates take place on the main thread, you should try
performSelectorOnMainThread:withObject:waitUntilDone: