Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITabBarController应用程序和pushViewController失败_Ios_Iphone_Objective C_Uinavigationcontroller_Uitabbarcontroller - Fatal编程技术网

Ios UITabBarController应用程序和pushViewController失败

Ios UITabBarController应用程序和pushViewController失败,ios,iphone,objective-c,uinavigationcontroller,uitabbarcontroller,Ios,Iphone,Objective C,Uinavigationcontroller,Uitabbarcontroller,我创建了一个TabBarController应用程序,里面有三个ViewControllers,分别是UINavigationControllers、a、B和C。我以编程方式创建了所有内容。现在,我想将一些ViewController推到其中一个选项卡项中 例如,如果我在ViewController B中,按下一个按钮,我想将ViewController按到ViewController:D,如果我在D中按下new按钮,我想转到一个新的ViewController E。无论何时,只要我想,我都可以

我创建了一个
TabBarController
应用程序,里面有三个
ViewControllers
,分别是
UINavigationControllers
、a、B和C。我以编程方式创建了所有内容。现在,我想将一些ViewController推到其中一个选项卡项中

例如,如果我在ViewController B中,按下一个按钮,我想将ViewController按到ViewController:D,如果我在D中按下new按钮,我想转到一个新的ViewController E。无论何时,只要我想,我都可以通过NavigationController back按钮返回

问题是,当我尝试从D返回B时,我在D和B之间有一个新的空ViewController,我得到以下错误:

首先,我在B中,按下下一步按钮到D:

2013-10-30 01:00:07.076 Wplanet[11964:70b] nested push animation can result in corrupted navigation bar
2013-10-30 01:00:07.444 Wplanet[11964:70b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2013-10-30 01:00:07.582 Wplanet[11964:70b] Unbalanced calls to begin/end appearance transitions for <DViewController: 0x8aa7260>.
我尝试过这样做:

appDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // TAB BAR CONTROLLER
    UITabBarController *tabBarController = [[UITabBarController alloc] init];


     AViewController *aVC = [[AViewController alloc] init];

    // nombre tab abr controller
    aVC.title = @"A";


    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:aVC];

    nav1.navigationBar.topItem.title = nil;



    BViewController *bVC = [[BViewController alloc] init];
    bVC.title = @"bVC";

    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:sherpaVC];
    nav2.navigationBar.topItem.title = nil;


    CViewController *cVC = [[CViewController alloc] init];
    cVC.title = @"cVC";

    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:cVC];
    nav3.navigationBar.topItem.title = nil;


    [tabBarController setViewControllers:@[nav1,nav2,nav3]];
    [tabBarController setSelectedIndex:1];

  self.window.rootViewController   = tabBarController;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;
}
BViewController代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(75, 75, 200, 14)];
    [titleLbl setTextColor:UIColorFromRGB(0x7B2F19)];
    [titleLbl setFont:[UIFont systemFontOfSize:14]];
    [titleLbl setBackgroundColor:[UIColor clearColor]];
    [titleLbl setText:@"I am in Bcontroller"];
    [self.view addSubview:titleLbl];

    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(75, 175, 200, 14)];
    [btn setBackgroundColor:[UIColor blueColor]];
    [btn setTitle:@"Next" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(next) forControlEvents:UIControlEventAllTouchEvents];
    [self.view addSubview:btn];

}


-(void)next
{
     DViewController *dVC = [[DViewController alloc] init];
        [self.navigationController pushViewController:dVC animated:YES];
}

您的问题是使用UIControlEventAllTouchEvents作为addTarget:action:forControlEvents:方法中的参数。这会导致“next”方法被调用两次。将其更改为UIControlEventTouchUpInside,它应该可以正常工作。

什么是sherpaVC和profileVC?我看不出您在哪里创建了这两个控件,并且您将sherpaVC设置为其中一个导航控制器的根视图控制器,但我看不到您对profileVC做了任何操作。抱歉,复制问题。。
- (void)viewDidLoad
{
    [super viewDidLoad];

    UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(75, 75, 200, 14)];
    [titleLbl setTextColor:UIColorFromRGB(0x7B2F19)];
    [titleLbl setFont:[UIFont systemFontOfSize:14]];
    [titleLbl setBackgroundColor:[UIColor clearColor]];
    [titleLbl setText:@"I am in Bcontroller"];
    [self.view addSubview:titleLbl];

    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(75, 175, 200, 14)];
    [btn setBackgroundColor:[UIColor blueColor]];
    [btn setTitle:@"Next" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(next) forControlEvents:UIControlEventAllTouchEvents];
    [self.view addSubview:btn];

}


-(void)next
{
     DViewController *dVC = [[DViewController alloc] init];
        [self.navigationController pushViewController:dVC animated:YES];
}