我在不使用委託協議的情況下呈現modalviewcontroller。但是想使用委託協議解僱modalviewcontroller。解僱modalview不工作
基本上I M推modalviewcontroller這樣
- (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];
}
對於駁回modalview這樣
在ModalViewController.h委派協議和方法
@protocol ModalViewDelegate <NSObject>
-(void) dismissModalView:(UIViewController *) viewController;
@end
@interface Infoviewcontroller : UIViewController <ModalViewDelegate>
{
id<ModalViewDelegate> dismissDelegate;
}
@property (nonatomic, retain) id<ModalViewDelegate> dismissDelegate;
@end
在modalviewcontroller。 M檔
@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
但不知何故,在單擊完成按鈕時
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];
任何人有任何線索,我M在我的代碼或我在做錯誤的丟失它無法正常工作。幫助將非常感激。
感謝