i m presenting modalviewcontroller without using delegate protocol. But want to dismiss modalviewcontroller using delegate protocol.
Basically i m pushing modalviewcontroller like this
- (void)displayModalViewaction: (id) sender
{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[Infoviewcontroller alloc] init];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
UINavigationController *navigationController=[[UINavigationController alloc] init];
navigationController.navigationBar.tintColor = [UIColor brownColor];
[navigationController pushViewController:_viewController animated:YES];
[self.view addSubview:navigationController.view];
[_viewController release];
[navigationController release];
}
For dismissing modalview doing this
In the ModalViewController.h delegated protocol and method
@protocol ModalViewDelegate <NSObject>
-(void) dismissModalView:(UIViewController *) viewController;
@end
@interface Infoviewcontroller : UIViewController <ModalViewDelegate>
{
id<ModalViewDelegate> dismissDelegate;
}
@property (nonatomic, retain) id<ModalViewDelegate> dismissDelegate;
@end
In modalviewcontroller. m file
@synthesize dismissDelegate;
-(void) dismissModalView:(UIViewController *) viewController;
{
[self dismissModalViewControllerAnimated:YES];
}
@end
-(void) dismissView: (id)sender
{
[delegate dismissModalView:self];
}
-(void) dismissModalView:(UIViewController *) viewController;
{
[self.dismissModalViewController Animated:YES];
}
@end
But somehow it is not working when clicking on done button
UIButton* backButton = [UIButton buttonWithType:101];
[backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"Done" forState:UIControlStateNormal];
// create button item
UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
// add the button to navigation bar
self.navigationItem.leftBarButtonItem = backItem;
[backItem release];
Anyone have any clue that what i m missing in my code or what i m doing wrong. Help will be really appreciated.
Thanks
I would have liked to comment, but not enough privilege. Anyways AFAIK…
One does not ‘push’ a modal VC… it needs to be ‘presented’ like this..
Only a presented Modal VC will get dismissed on calling
[self dismissModalViewControllerAnimated:YES];OR, in case you really need to ‘push’ it.. then you need to ‘pop’ it to get back!
Hope it helps