views:

52

answers:

2

Hi all,

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.

A: 

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
A: 

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.

macatomy