【问题标题】:Change ViewController on AlertView click在 AlertView 上单击更改 ViewController
【发布时间】:2014-07-10 13:58:57
【问题描述】:

我正在开发一个选项卡式应用程序。

我有 2 个视图控制器:ViewControllerA、ViewControllerB。

ViewControllerA 是一个标签栏控制器,而 ViewControllerB 是一个普通的 ViewController。

在 ViewController A 上,会出现一个警报视图,当单击其中一个按钮时,它应该转到 ViewControllerB:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Anything"])
   {
        ViewControllerB *controllerB = [self.storyboard istantiateViewControllerWithIdentifier:@"ViewControllerB"]
        [self presentViewController:controllerB animated:YES completion:nil];

    }
}

现在,在不是选项卡栏控制器的 ViewControllerB 上,当我按下按钮时,它应该转到 ViewControllerA,并且选项卡栏应该再次出现。 方法如下:

ViewControllerA *controllerA = [self.storyboard istantiateViewControllerWithIdentifier:@"ViewControllerA"];

[self presentViewController:controllerA animated:YES completion:nil];

问题是,当我按下 ViewControllerB 上的按钮时,应该将我带到选项卡栏控制器,它确实切换到 ViewControllerA,但选项卡栏没有出现。

因此,我们将不胜感激。

【问题讨论】:

  • 显示视图控制器的方式有很多种。提供大量教程。
  • 所以你的问题真的与警报视图无关,对吗?如果您不知道如何呈现视图控制器,请阅读`iOS 视图控制器编程指南"。
  • 我已经更新了帖子。
  • @MohamedGooner 最好删除此帖子并重新发布问题。

标签: ios objective-c ios7 uiviewcontroller


【解决方案1】:

按下ViewControllerB 上的按钮时,您应该编写以下代码:

(void)buttonPressed
{
 [self dismissViewControllerAnimated:NO completion:nil];
}

【讨论】:

    【解决方案2】:

    假设您的 ViewControllerA 已经拥有自己的导航控制器,一个简单的方法是实例化新的视图控制器并使用您的导航控制器将其推送到堆栈中:

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
        NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
        if ([title isEqualToString:@"Anything"]) {
            ViewControllerB *viewControllerB = [[ViewControllerB alloc] init];
            [self.navigationController pushViewController:viewControllerB animated:YES];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多