Crystal
Crystal

Reputation: 29518

Displaying UIAlertView from a non-view class

I'm looking at a friend's code and not sure how this works. There's a singleton that talks to a web service to download data. The WebServiceObject is a subclass of NSObject. The download comes from a click on the home page which is a UIViewController.

In the WebServiceObject, when something goes wrong, he does:

UIAlertView *alert = [[UIAlertView alloc] init...];
[alert show];

The alert shows. How does that alert show though since the code that executes it is a non-view object? The reason I'm asking is because I want to remove that alert when the network comes back on. Since the network observing is happening in the WebServiceObject, I'm not sure how to access the UIAlertView object. I thought in other code I've done, that I would do something like

[self.view viewWithTag:NETWORK_ALERT_TAG];

or something to that affect. Is this because the view code is in the model code and instead I should change his code to post a notification to the view code to display the alert instead and grab it that way? Thanks a bunch!

Upvotes: 0

Views: 261

Answers (2)

CStreel
CStreel

Reputation: 2642

It sounds like you want to have the UIAlertView without any buttons, I found this nice tutorial that presents a "Please Wait Alert"

http://mobiledevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html

I think it will help you achieve what you want, if you don't want the user to be able to dismiss the alert

Upvotes: 0

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

UIAlertView’s -show method creates its own window, overlaid on top of the app’s window, in which to display itself; as such, it isn’t part of the app’s view hierarchy. To hide it, you’ll need a reference to the alert view itself, maybe exposed as a property on your WebServiceObject.

Upvotes: 1

Related Questions