0

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

user379468
  • 3,989
  • 10
  • 50
  • 68

1 Answers1

0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Can you even add a button to the tab bar controller's view? – rdelmar Mar 08 '13 at 17:44
  • @rdelmar Apparently since he is. :) – rmaddy Mar 08 '13 at 17:46
  • I tried it -- you can, but it shows on top of the views of all the contained controllers. This is not a good design. – rdelmar Mar 08 '13 at 17:49
  • @rdelmar That's a separate question for the OP to deal with. This one is all about getting the button's action working. – rmaddy Mar 08 '13 at 17:52
  • I'm implementing a custom button for the center (This is something I have seen quite often) Since the button is larger than the tab bar, there is really no other way to make it work – user379468 Mar 08 '13 at 18:49
  • @rmaddy after reading through this like 5 times, my eye finally caught the trailing : in the method name .... it's little thing like this that kill me – user379468 Mar 08 '13 at 18:53