簡體   English   中英

模態窗口沒有被解雇

[英]Modal window not being dismissed

我有兩個以編程方式創建的按鈕,您可以在我的viewDidLoad方法中看到。 在模態窗口中,我有一個通過委托調用cancelSearch方法的按鈕。 當我在cancelSearch方法上放置一個斷點時,它被命中,所以我知道我的委托設置正確,但即使它調用了這一行[self dismissViewControllerAnimated:YES completion:nil]; 它實際上並沒有關閉模態窗口。

以下代碼全部來自我的主控制器視圖。

- (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];
}

您可以使用類似於以下內容的方式關閉模態視圖:

[self dismissModalViewControllerAnimated:YES];

這將取消使用類似於以下內容加載的模態視圖:

[self presentModalViewController:search animated:YES];

但是,查看您的代碼片段,看起來搜索視圖控制器正在使用以下行推送到導航堆棧:

[self.navigationController pushViewController:search animated:YES];

所以我可能需要從導航堆棧中彈出視圖,而不是試圖將其視為模態視圖:

[self.navigationController popViewControllerAnimated:YES];

如果您的視圖控制器是模態呈現的,您應該使用:

[self.presentingViewController dismissModalViewControllerAnimated:YES];

presentsViewController屬性僅在iOS 5中可用。 因此,如果您的目標是舊版本的iOS,則必須使用self.parentViewController(對每個iOS版本使用適當的版本,您必須處理此問題)。

如果在父/呈現視圖控制器中進行此控制,則只需調用:

[self dismissModalViewControllerAnimated:YES];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM