Changing a view after modalViewController is dismissed (Cocoa Touch) - objective-c

I have a viewController that presents a modalViewController when a UINavigationBarItem is touched. After the user is done with the modal view, the modalViewController is dismissed. At this point I want to change/remove the NavigationBarItem -- how would I accomplish this?
I was thinking of using viewWillAppear: but I only want the change to happen when the modalViewController is dismissed.

One way is to use NSNotificationCenter.
Before presenting the modal view, call addObserver to prepare to be notified.
At the place where the modal view is dismissed, post a notification using postNotificationName.
The notification will call a method you specify in addObserver.
In this method, put your "modal view dismissed" logic.

Related

Performing action in root view controller after dismissing modal view controller

If I wanted to perform some sort of action right after dismissing a modal view controller, where exactly would I put the code? I know it wouldn't be in viewDidLoad because the rootviewcontroller was already loaded into memory (because it was just temporarily hidden by the modal view) and I'm not sure about viewWillAppear or viewDidAppear because of course the view has already been loaded into memory.
ViewWillAppear will be called again in caller view controller when modal is dismissed, so with some logic can be a good place.
Otherwise you can think about implementing a delegate, or if synchronicity is not an option to be considered, you can send a custom NSNotification to be catched by the modal caller.

Reloading UIModalViewControllers

I have a super simple presentation for iPad with few modal views. At every View user makes a simple action (like dragging a slider), after that appears UIButton "Next" what presents new modal View above previous. Button in last view connects with first view by a modal segue. So app needs to work in recursive way. But after first time presentation goes (from the second loop starts), all Views presented with all actions done in them. So I want that all app ModalViewControllers reloads to the default state every time user taps button on the last View.
Can I implement this behaviour only set it in -prepareForSegue of UIButton in last ModalViewController or it's a more global issue? If so, how to implement that?
Implement viewWillAppear in every ViewController will give you an opportunity to reset the view before the view gets to the screen. When you come back to a ViewController from another viewController, viewWillAppear gets called.
-(void)viewWillAppear:(BOOL)animated
{
NSLog(#"viewWillAppear");
[super viewWillAppear:animated];
//Reset your view (i.e. hide next button etc.)
}

Dismiss custom modal view controller

I'm developing an iPad app where I've created a custom segue to present my view controller with a custom animation. It's now working (almost) fine and in the end it looks like a form modal view controller, exactly how I wanted it to look.
Now I need to create a custom animation for dismissing the modal view controller that matches the first animation.
What is the best way to do it? I have my custom animation inside my custom segue and I think the reverse animation should be there also. But I also think the segue is not the place to have it.
How'd you guys do it?
Thanks
Unfortunately you can't use the segue to perform the dismiss of your modal ViewController its jut one way (will change in ios6). just perform your custom dismiss-animation and call dismissModalViewControllerAnimated:NO on the parentViewController in the finished block of the animation.

Background UIViewController loading when ModalViewController is in the foreground (iOS)

I'm not sure why this is happening, but in the App delegate, I'm setting a viewcontroller as the root and presenting a ModalViewController in front of it. The strange thing is that the viewcontroller behind the modalviewcontroller is still loading even though it does not appear. Is this normal? Is there a way to prevent the viewcontroller behind the modalviewcontroller to load?
Thank you
I am not sure exactly what you mean by "loading." As long as the view controller in the background is the parent view controller of the modal view controller, it is going to need be initialized before the modal view controller can be displayed at all. In that sense, it must be loaded.
If, on the other hand, you mean that the contents of the background view controller are visually displayed and then, afterwards, the model view controller appears on top of it—but you don't want the contents of the background controller to be seen until after the modal view controller is dismissed—then one possibility would be to set the hidden property to YES and unhide the contents when modal view controller is dismissed. To do that, I would make the background view controller a delegate of the modal view controller, so it receives a callback when the modal view controller is dismissed.

Show UIAlertView in viewDidDisappear: buttons not reacting?

In viewDidDisappear: of a modally presented controller I added a callback to inform who ever is interested about the view being gone (after the animation has finished) without requiring subclassing.
One of my controllers that registered for the callback is firing up a UIAlertView in there. However, once the alert is shown, its buttons don't react.
Another one is adding a subview to itself and again: the buttons of the view don't react.
The resposible handlers of the buttons are not triggered.
I assume it has to do with the fact that viewDidDisappear: is not really finished yet when it call my callback. But even if I used subclassing instead, it would be the same situation.
One explanation could be that there is still some other view covering my buttons because the clicks just don't come through.
So: Can somebody confirm that it is NOT a good idea to do what I am doing (showing an alert, adding a subview in viewDidDisappear), because then I will have to change the flow. If it should be okay, I have to figure out what else is causing this effect.
I'd put the callback into viewWillDisappear: instead. At least then the original UIView reference is still around.
Better solution would be to dismiss the modal view through the parent controller by adding the caller as a delegate. The delegate would implement a protocol to dismiss the modal controller. Call the delegate protocol from the modal view, when you are ready to dismiss.
To avoid changing the flow, you could schedule a timer to show the alert, this will give a chance to the view controller code to complete