-1

我在这里阅读了很多主题,但不明白。例如,我有两个 ViewController。VC1 和 VC2。如何以编程方式从 VC1 转到 VC2?我用 NSURLConnection 加载数据,然后解析它,如果在收到的数据中我看到字符串“type=1”,我必须运行另一个 ViewController,它必须运行它的所有方法(ViewDidLoad 等)。我该怎么做?

在 VC1 中,我有:

If ([[_typeArr objectAtIndex:0]] intValue] == 1)
   //Here I must to run VC2
4

5 回答 5

1

首先,您需要#import VC2.hVC1.m文件中添加您的文件并编写以下代码

if ([[_typeArr objectAtIndex:0]] intValue] == 1)
{
   VC2 *vc2 = [[VC2 alloc] init]; // create object of VC2
   [self presentViewController:vc2 animated:YES completion:nil]; 
            OR // if you have to use navigation controller then
   [self.navigationController pushViewController:vc2 animated:YES];
}
于 2013-11-14T11:01:48.670 回答
0

以下是将新视图控制器推送到导航控制器堆栈的代码。希望这是您正在寻找的。

UIViewController *viewController = [[[UIViewController alloc] init] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
于 2013-11-14T11:01:24.463 回答
0

这取决于 - 如果您使用故事板构建您的应用程序,您应该使用以下方法触发一个序列:

performSegueWithIdentifier:.

如果您不使用情节提要并且正在使用 UINavigationController ,则应该通过以下方式触发:

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

您是否没有使用 NavigationController 可能 UIModalViewController 对您来说是正确的答案。

那真的取决于..但我强烈建议您使用故事板和segue。有非常棒的,并且连接UINavigationController是自己创建的。

于 2013-11-14T11:03:49.413 回答
0
1. If your Application is using Navigation controller Without Storyboard try this:

if ([[_typeArr objectAtIndex:0]] intValue] == 1)
{
    VC2 *vc2 = [[VC2 alloc] initWithNibName:@"VC2"]; // create object of VC2
    [self.navigationController pushViewController:vc2 animated:YES];
}

2.If your Project is not using neither Navigation controller nor Storyboard try this:
 if ([[_typeArr objectAtIndex:0]] intValue] == 1)
   {
     VC2 *vc2 = [[VC2 alloc] initWithNibName:@"VC2"]; // create object of VC2
     [self presentViewController:vc2 animated:YES completion:nil]; 
}

3.If your Project is using Navigation controller and Storyboard Follow This Step:

      1.In Storyboard File > Go to Your First View Controller on left Side  >> Right Click >> Give   Connection From Manual to Second View Controller (Under Trigger Segue)

As Result Connection is created With Arrow In Circle 

Click On Arrow Button (If you can not see that arrow Zoom out  storyboard file) 

On Right Side Click on Attribute Inspector 

Give Identifier Name "VC2"


Now in Code Part:

if ([[_typeArr objectAtIndex:0]] intValue] == 1)
{
   [self performSegueWithIdentifier:@"VC2" sender:nil]; // Must Be Same as given In Identifier field in storyboard
}
于 2013-11-14T12:08:19.643 回答
-1

只需查看导航控制器的教程,因为您需要一个可以保持导航从一个到另一个的容器控制器,这里有一些链接可以返回,如果您遇到特定问题,请返回。

http://www.ralfebert.de/archive/ios/tutorial_iosdev/navigationcontroller/

http://www.techotopia.com/index.php/Creating_a_Navigation_based_iOS_5_iPhone_Application_using_TableViews

http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/

于 2013-11-14T11:01:34.683 回答