2012-01-16 34 views
0

我在不使用委託協議的情況下呈現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在我的代碼或我在做錯誤的丟失它無法正常工作。幫助將非常感激。

感謝

回答

1

我想評論,但沒有足夠的特權。反正據我所知......

一不「推」模態VC ...它需要被「提交」這樣的..

[navigationController presentModalViewController:_viewController animated:YES]; 

僅呈現模態VC上調用[self dismissModalViewControllerAnimated:YES];將獲得解僱

或者,如果您確實需要「推」它,那麼您需要「彈出」它才能找回!

希望它可以幫助

1

糾正我,如果我錯了,但你不希望在您的.h文件中定義_viewController,並駁回:[delegate dismissModalView:_viewController];而不是解僱自己,因爲自己不是一個視圖控制器。

1

你是推到導航的堆棧所以沒有莫代爾已經顯示過,你需要彈出堆棧的看法:而非

[self.navigationController popViewControllerAnimated:YES]; 

[self dismissModalViewControllerAnimated:YES];