Jelle
Jelle

Reputation: 294

UIView - NSURLConnection doesn't call delegates

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.

Upvotes: 1

Views: 248

Answers (2)

Costique
Costique

Reputation: 23722

First of all, it's not enough to add <NSURLConnectionDelegate> to your object's interface declaration, you should explicitly set it as the NSURLConnection's delegate.

Secondly, UIView is definitely a wrong candidate as an NSURLConnection delegate, because:

  • UIView is the view part of MVC;
  • the view may be unloaded unless you take extra measures like retaining it in the UIViewController.

That makes UIViewController a better choice as an NSURLConnection delegate.

Upvotes: 1

dom
dom

Reputation: 11972

You should do this in your UIViewController. Take a look at Apples documentation:

The UIView class defines a rectangular area on the screen and the interfaces for managing the content in that area. At runtime, a view object handles the rendering of any content in its area and also handles any interactions with that content.[…]

So UIView is not the correct place to do stuff like interaction with a server.

Upvotes: 1

Related Questions