Question

I have a UITabBarController bassed app. I'm instantiating it from the app delegate and adding a custom button in the tab bar controller. when that button is clicked, I want to present another view modally, but I cant seem to figure out how to do it. to add the button I'm basically doing this

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[self.tabBarController.view addSubview:button];
[button addTarget:self action:@selector(showModalViewController:) forControlEvents:UIControlEventTouchUpInside];

and also in the app delegate I have a method

- (void) showModalViewController {
    DummyViewController *addController = [[DummyViewController alloc]
                                                initWithNibName:@"DummyViewController" bundle:nil];
    //addController.delegate = self;

    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];


    // Create the navigation controller and present it modally.
    [self.tabBarController.selectedViewController presentModalViewController:addController animated:YES];

    // The navigation controller is now owned by the current view controller
}

I keep getting unrecognized seletor

Was it helpful?

Solution

Your selector looks for a method named showModalViewController: but your actual method is named showModalViewController. Change one or the other.

Either change the selector to @selector(showModalViewController) to match the existing method, or change the method to:

- (void)showModalViewController:(UIButton *)button {

Don't change both.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top