1
votes

So my current app uses UIAlertView in a few places and upon updating to iOS 8 I saw the notes in the documentation once saying that UIAlertView (and UIActionSheet) had been deprecated since iOS 8 and replaced with UIAlertController. I added it to my todo list and have just started to tackle refactoring my code over to use the new UIAlertController class.

I can see how everything works with the UIAlertController though I'm left with a few use cases of UIAlertView which I don't seem to easily be able to replace with UIAlertController. This all stems from the fact that [UIAlertView show] was callable as is to display an alertView, where as the UIAlertController must be presented from another viewController using the presentViewController method. The problem is that I have a number of calls to create alertViews that are coming from code not directly linked to a particular viewController, I'm going to have to refactor and pass through viewController params to each calling point to be able to use the UIAlertControllers. Before I do this I wondered if anyone knew of a nice way to get back the ability to just display the UIAlertController without knowing a suitable ViewController at the time. Is there a way to get the "current view controller" from something?

I've also implemented a debug alert view macro which lets me put up error messages within alert views, these can obviously be called from anywhere and unlike actual app functionality providing alertViews I really don't want to have to refactor ViewControllers throughout all my code just to use them.

It's a little frustrating that whilst deprecating some systems they've not provided functionality that allows the replacement system to be used in the same way as the original functionality.

Any help appreciated!

1

1 Answers

0
votes

In the end I solved this issue by having all my viewControllers register themselves whenever they WillAppear as the current viewController. Then whenever I needed to present an alert I had a viewController on hand to present the alert from.

Not ideal and perhaps some holes in the logic if an alert was required at an awkward time as views transitioned, but it seemed to work and wasn't that messy.

Frustrated that this aspect of the API was just removed.