UIView - NSURLConnection 不调用委托
我正在使用 Objective-C 类 (UIView
)。在该类中,我调用 NSURLConnection
(将 NSURLConnectionDelegate 添加到 .h)当我启动连接时,没有任何反应。它没有调用它的方法。是否无法在 UIView
类中调用 NSURLConnection
或者我做错了什么?
谢谢。
I'm using an Objective-C class (UIView
). In that class I'm calling an NSURLConnection
(added NSURLConnectionDelegate to .h) When I start the connection, nothing happens. It's not calling its methods. Is it just not possible to call NSURLConnection
in a UIView
class or am I doing something wrong?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,仅将
添加到对象的接口声明中是不够的,您应该显式地将其设置为NSURLConnection
的委托。其次,
UIView
绝对是一个错误的候选NSURLConnection
委托,因为:UIView
是 MVC 的视图部分;UIViewController
中。这使得 UIViewController 成为
NSURLConnection
委托的更好选择。First of all, it's not enough to add
<NSURLConnectionDelegate>
to your object's interface declaration, you should explicitly set it as theNSURLConnection
's delegate.Secondly,
UIView
is definitely a wrong candidate as anNSURLConnection
delegate, because:UIView
is the view part of MVC;UIViewController
.That makes
UIViewController
a better choice as anNSURLConnection
delegate.您应该在 UIViewController 中执行此操作。看看苹果的文档:
因此 UIView 不是执行与服务器交互之类的操作的正确位置。
You should do this in your UIViewController. Take a look at Apples documentation:
So UIView is not the correct place to do stuff like interaction with a server.