我有兩個編程創建的按鈕,您可以在我的viewDidLoad方法中看到。在模態窗口中,我有一個按鈕,通過委託調用cancelSearch方法。當我在我的cancelSearch方法上放置一個斷點時,它被擊中,所以我知道我的委託設置正確,但即使它調用這一行[self dismissViewControllerAnimated:YES completion:nil];它實際上並沒有關閉模態窗口。Modal窗口不被解僱
以下代碼全部來自我的主控制器視圖。
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showActionMenu:)];
actionButton.style = UIBarButtonItemStyleBordered;
UIBarButtonItem *searchButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(showSearchMenu:)];
searchButtonItem.style = UIBarButtonItemStyleBordered;
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 103.0f, 44.01f)];
NSArray* buttons = [NSArray arrayWithObjects:actionButton, searchButtonItem, nil];
[toolbar setItems:buttons animated:NO];
self.navigationItem.title = @"Census Management";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[[RKClient sharedClient] get:@"censusmanagement" delegate:self];
}
- (IBAction)showActionMenu:(id)sender
{
[self performSegueWithIdentifier: @"CMActionSegue" sender: self];
}
- (IBAction)showSearchMenu:(id)sender
{
ehrxCMSearchView *search = [[self storyboard] instantiateViewControllerWithIdentifier:@"cmSearch"];
search.selectedOptions = self.selectedOptions;
search.delegate = self;
[self.navigationController pushViewController:search animated:YES];
}
- (void)cancelSearch:(ehrxCMSearchView *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
我認爲你是對的。我改變了它,因爲我傳遞了它的數據。所以我這樣做的方式,我想這甚至是一個模態的觀點了。由於我有我的委託設置,我可以從主視圖控制器嗎?那裏的最後一行看起來像我會從我展示的新視圖中執行。 – Jhorra 2012-03-21 19:17:42
關於它的更多思考,我猜是因爲我推動視圖而不是將其視爲模式,我應該能夠將數據傳回主控制器,然後手動從後者調用返回功能。 – Jhorra 2012-03-21 19:21:06
@Jhorra您可以從主視圖控制器或新視圖控制器調用-popViewControllerAnimated:因爲它們(理論上)應該使用相同的UINavigationController。對於模態視圖,您需要從呈現模態視圖控制器(很可能是您的主視圖控制器)的視圖中調用-dismissModalViewControllerAnimated。 – 2012-03-21 19:49:51