簡體   English   中英

解雇一個視圖控制器並提出另一個viewController

[英]dismissing a view controller and presenting another viewController

在我的應用程序中,我有4個UIViewcontrollers -A,B,C和D。

從我的UIViewController A可以顯示UIVIewControllers B或C或D。 假設,從A開始,我呈現了B。然后,在B上,有兩個UIButtons ,單擊它們,我需要關閉B和Present C或關閉B和PresentD。這是成功發生的,但首先是在關閉之后B,出現A的屏幕,然后轉到C或D。

這是我所做的:

在按鈕上按B,操作是:

{
    UINavigationController *controller = (UINavigationController *)self.parentViewController;
    NSLog(@"%@",[controller parentViewController]);
    UITabBarController *tabBarReference = (UITabBarController *)[controller parentViewController];

    HomePageViewController *presController = (HomePageViewController *)tabBarReference.presentingViewController;
    [presController dismissTabControllerWithHandlerWithSenderAtIndex:1];
}

在A中,我有以下方法:

-(void)dismissTabControllerWithHandlerWithSenderAtIndex:(NSInteger)index
{
    if(index == 0)
    {
        [self dismissViewControllerAnimated:NO completion:^{

            [self aboutButtonPressed:self];

        }];
    }

    else
    {
        [self dismissViewControllerAnimated:NO completion:^{

            [self settingsButtonPressed:self];

        }];
    }
}

這是我正在打電話的方法。

- (IBAction)settingsButtonPressed:(id)sender
{
    [self.contactUsView setHidden:YES];

    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    NSString *deviceType = [prefs objectForKey:@"DeviceType"];
    NSString *iOSType = [prefs objectForKey:@"iOSType"];

    if([iOSType isEqualToString:@"iOS7"])
    {
        if([deviceType isEqualToString:@"iPad"])
        {
            SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPad" bundle:NULL];
            settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
            [self presentViewController:settingsPage animated:YES completion:NULL];
        }

        else
        {
            SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:NULL];
            settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
            [self presentViewController:settingsPage animated:YES completion:NULL];
        }
    }

    else
    {
        if([deviceType isEqualToString:@"iPad"])
        {
            SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iPad_iOS6" bundle:NULL];
            settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
            [self presentViewController:settingsPage animated:YES completion:NULL];
        }

        else
        {
            SettingsViewController *settingsPage = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController_iOS6" bundle:NULL];
            settingsPage.modalTransitionStyle = UIModalTransitionStylePartialCurl;
            [self presentViewController:settingsPage animated:YES completion:NULL];
        }
    }
}

好吧,去:-

假設viewcontroller A是基&它presents任一view controllers B或C.

在必須關閉視圖控制器B或C的地方實現委托/通知。

發送委托或發布通知后,關閉view controller without animation, ie animation:NO的當前view controller without animation, ie animation:NO

需要在view controller A中聽到已發布的此通知。

在這里,您將展示下一個視圖控制器。

編輯:-

-(void)dismissTabControllerWithHandlerWithSenderAtIndex:(NSInteger)index
{
    if(index == 0)
    {
        [self dismissViewControllerAnimated:NO completion:nil];
        [self aboutButtonPressed:self];

    }

    else
    {

        [self dismissViewControllerAnimated:NO completion:nil];
        [self settingsButtonPressed:self];
    }
}

暫無
暫無

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

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