Noobie iOS developer with an adopted iOS app here.
I have a settings piece of an iOS app and when the user clicks done, I want the modal view controller (which it currently does) and I want to call a function called updateMainUI in the presentingViewController.
Here's the method I am calling:
- (void)done:(id)sender
{
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]; // works
[[self presentingViewController updateMainUI]; //doesn't work
But I get the following error:
No visible @interface for 'UIViewController' declares the selector 'updateMainUI'
But I have declared this in the presenting controller
@interface LocationsViewController : UITableViewController <CLLocationManagerDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
-(void)updateMainUI;
But it's odd that the error should be about UIViewController when the presenting controller is a UITableViewController.
Any ideas on how to get the updateMainUI working? And what I'm doing wrong?
thx
edit #1 This is how I'm creating this - any idea how to get a refernce to the *nearbyViewController?
UIViewController *nearbyViewController = [[LocationsViewController alloc] initWithNearbyLocations];
UINavigationController *nearbyNavigationController = [[UINavigationController alloc] initWithRootViewController:nearbyViewController];
...
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:nearbyNavigationController, browseNavigationController, eventsNavigationController, nil];
Crud, I see the real answer now. It's a casting problem. Try this:
You need to be very certain that
-presentingViewController
returns an object of type LocationsViewController or you will have bigger problems on your hands.After dismissing ones
self
, you should expectself.presentingViewController
to becomenil
. Try callingupdateMainUI
just before dismissing.[[self presentingViewController updateMainUI]
is broken and won't compile. Assuming you meant[[self presentingViewController] updateMainUI]
, then there are other ways of doing it.Using the variable presenting is an important step.