简体   繁体   English

解雇一个视图控制器并提出另一个viewController

[英]dismissing a view controller and presenting another viewController

In my application, I have 4 UIViewcontrollers - A, B, C and D. 在我的应用程序中,我有4个UIViewcontrollers -A,B,C和D。

From my UIViewController A , UIVIewControllers B or C or D can be presented. 从我的UIViewController A可以显示UIVIewControllers B或C或D。 Suppose, from A, i have presented B. Then, on B, there is are two UIButtons , clicking on which, i need to dismiss B and Present C or dismiss B and Present D. This is happening successfully, but first, after dismissing B, the screen of A comes, and then it goes to C or D. 假设,从A开始,我呈现了B。然后,在B上,有两个UIButtons ,单击它们,我需要关闭B和Present C或关闭B和PresentD。这是成功发生的,但首先是在关闭之后B,出现A的屏幕,然后转到C或D。

Here's what i did: 这是我所做的:

On Button Press On B, the action is: 在按钮上按B,操作是:

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

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

In A, i have these methods: 在A中,我有以下方法:

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

            [self aboutButtonPressed:self];

        }];
    }

    else
    {
        [self dismissViewControllerAnimated:NO completion:^{

            [self settingsButtonPressed:self];

        }];
    }
}

Here's the method i am calling.. 这是我正在打电话的方法。

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

Ok here goes:- 好吧,去:-

Suppose viewcontroller A is the base & it presents either view controllers B or C. 假设viewcontroller A是基&它presents任一view controllers B或C.

Implement delegate/notifications where the view controller B or C has to be dismissed. 在必须关闭视图控制器B或C的地方实现委托/通知。

After sending the delegate or posting the notification, dismiss the current view controller without animation, ie animation:NO . 发送委托或发布通知后,关闭view controller without animation, ie animation:NO的当前view controller without animation, ie animation:NO

This notification that was posted needs to be heard in view controller A. 需要在view controller A中听到已发布的此通知。

Here you present the next view controller. 在这里,您将展示下一个视图控制器。

EDIT:- 编辑:-

-(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.

相关问题 解雇另一个后呈现模态视图控制器 - Presenting a modal view controller after dismissing another 在展示另一个时解雇ViewController - Dismissing ViewController while presenting another one 解散View Controller,然后显示一个Alert Controller - Dismissing a View Controller, then presenting an Alert Controller iOS 8 - 在设置关键窗口后快速显示视图控制器或解除并立即显示另一个视图控制器时出现故障 - iOS 8 – Glitch when presenting view controller quickly after setting key window or dismissing and instanly presenting another 消除呈现模态ViewController - Dismissing presenting modal ViewController 在加载另一个ViewController时呈现模态视图控制器 - Presenting a modal view controller when loading another ViewController 解除 UIImagePickerController 也解除呈现视图控制器 - Dismissing of UIImagePickerController dismisses presenting view controller also 同时解雇一个视图控制器,然后展示一个 - Simultaneously dismissing a view controller and then presenting one 关闭presentedViewController也会关闭呈现视图controller - Dismissing presentedViewController also close the presenting view controller 提供两个视图控制器,关闭正确的视图控制器 - Presenting two view controller, dismissing correct view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM