neha
neha

Reputation: 6377

Modal viewController dismiss button problem

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.

Upvotes: 0

Views: 1191

Answers (2)

indragie
indragie

Reputation: 18132

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.

Upvotes: 1

iwasrobbed
iwasrobbed

Reputation: 46713

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

[self.parentViewController dismissModalViewControllerAnimated:YES];

Upvotes: 1

Related Questions