0

I'm creating a simple modal ViewController. I'm creating a nib with a button and on that button press calling a method to display modal viewController in which I'm creating the viewController and a button inside it like this.

UIViewController *modalViewController = [[UIViewController alloc]initWithNibName:nil bundle:nil];
modalViewController.view.backgroundColor = [UIColor redColor];
modalViewController.;

UIButton *btnDismissViewController = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnDismissViewController.frame = CGRectMake(60, 160, 150, 50);
[btnDismissViewController setTitle:@"DISMISS" forState:UIControlStateNormal];
[btnDismissViewController addTarget:self action:@selector(dismissViewCOntroller) forControlEvents:UIControlEventTouchUpOutside];

btnDismissViewController.backgroundColor = [UIColor grayColor];
[modalViewController.view addSubview:btnDismissViewController];

[self presentModalViewController:modalViewController animated:YES];

This view is appearing properly but after pressing the button on modalViewController, the target method for dismissing the modalViewController isn't called. I'm definitely missing something obvious but not getting what. Can anybody please help?

Thanx in advance.

neha
  • 6,327
  • 12
  • 46
  • 78
  • Please show us the definition of the `dismissViewCOntroller` method. The way you defined the selector, it should look like this, with two capital letters and all: `- (void)dismissViewCOntroller` (no sender argument). – Ole Begemann Jun 26 '10 at 20:05
  • 1
    Also, are you sure you didn't mean to write `UIControlEventTouchUpInside`? – Ole Begemann Jun 26 '10 at 20:05
  • Thanx, Ole, IWasRobbed and Macatomy... Yes, there was a typo.. I should have written "UIControlEventTouchUpInside" which accidently was written as UIControlEventTouchUpOutside.. – neha Jun 28 '10 at 06:12
  • this Question is answered here [enter link description here][1] [1]: http://stackoverflow.com/questions/6557425/modal-view-controller-wont-dismiss-itself – Mohamed DiaaEldin Dec 08 '11 at 09:05

2 Answers2

1

I agree with Ole's comment... additionally, make sure you are dismissing it within your dismissViewCOntroller method similar to this:

[self.parentViewController dismissModalViewControllerAnimated:YES];
iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
1

I think there might be a typo in your code, dismissViewCOntroller seems like it should be dismissViewController, but maybe that was intentional, and the control state should be UIControlEventTouchUpInside.

indragie
  • 18,002
  • 16
  • 95
  • 164