intargc
intargc

Reputation: 3111

Is there a way to access the view controller that initiated a modal view from that new modal view?

I have a view that has an "Add" button in its navigation bar. When clicking that button, it slides up a modal view with a form for them to add their item. I would like to inform the calling view controller (the one that had the "Add" button) that the expense has been added so it can do any updating it needs to do. Is there any way to get access to the view controller that initiated the modal view?

Upvotes: 0

Views: 110

Answers (3)

D33pN16h7
D33pN16h7

Reputation: 2030

if you are in iOS 5.0 you should access this information with presentingViewController property, and for iOS 2.0 to 4.X parentViewController property works.

Upvotes: 0

timthetoolman
timthetoolman

Reputation: 4623

There are two ways that come to mind. Either create a protocol that your modal view uses to inform the calling viewController or by having your modal view post a NSNotification that the calling view controller is observing. In the case of posting the notification, you would send the expense in the userInfo dictionary of the NsNotification object.

Good luck

Upvotes: 2

Related Questions