Pregunta

I'm reviewing someone else's code and noticed a web form gets refreshed every time you attach an image(click 'add image', find and choose image, return to form, form goes blank). And, it's because the url gets reloaded. In tracking this issue down I noticed that the original dev overrode the viewDidAppear instance method in WebViewController like so:

- (void) viewDidAppear:(BOOL)animated {

    NSURL *url = [NSURL URLWithString:self.defaultUrl];

    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [self.webView loadRequest:requestObj];
}

Apple's documentation says

You can override this method to perform additional tasks associated with presenting the view. If you override this method, you must call super at some point in your implementation.

I see super isn't called and I think putting in an NSURLRequest is not good practice. I removed the code, added the URL call a button action and all's well so this is mostly a stylistic/academic question.

Do you agree that loadRequest shouldn't be in there? Thanks for your help.

¿Fue útil?

Solución

Why shouldnt it be there? loadRequest does its work asynchronously on another thread, so it doesn't block the main thread.

Connects to a given URL by initiating an asynchronous client request.

If it behaves the intended way, is for you to decide.

(Oh and yeah, you should call super in viewDidAppear)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top