1

我在推送视图控制器时遇到问题。这就是我所做的:单击按钮时,我使用此代码添加了一个模式视图,它工作正常:

- (void)addAction:(id)sender
{
    uipickerForContract *addViewController = [[uipickerForContract alloc] initWithNibName:@"uipickerForContract" bundle:nil];
    addViewController.delegate = self;

    addViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    addViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    [self presentModalViewController:addViewController animated:YES];

    addViewController.view.superview.frame = CGRectMake(50, 740, 695, 245);


}

这个添加的视图控制器包含一个完成按钮,我想使用它来导航到其他视图控制器:所以我使用了该代码但它不起作用,它只是关闭了 addeview:

 donebutton{

    nextview*s = [[nextview alloc]initWithNibName:@"nextview" bundle:nil];
    s.view.frame = CGRectMake(10, 20, 745, 755);
    //nextview contains the object that I want to pass :object
        s.object= self;
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self];
    [self dismissModalViewControllerAnimated:YES];
         [self.navigationController pushViewController:s animated:YES];
        NSLog(@"self.nav%@",self.navigationController);
     }
4

2 回答 2

0

视图控制器的 self.navigationController(您以模态方式呈现)将为 nil

而且您无法注意到这件事,因为您正在分配导航控制器对象。

于 2013-05-27T14:50:42.360 回答
-1

您需要在解雇和下一次推送之间延迟一些这样的事情

前 :

nextview*s = [[nextview alloc]initWithNibName:@"nextview" bundle:nil];
s.view.frame = CGRectMake(10, 20, 745, 755);
//nextview contains the object that I want to pass :object
    s.object= self;
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self];
[self dismissModalViewControllerAnimated:YES];
     [self.navigationController pushViewController:s animated:YES];
    NSLog(@"self.nav%@",self.navigationController);

后 :

[self dismissModalViewControllerAnimated:YES];
[self performSelector:@selector(pushNextView) withObject:nil afterDelaye:0.40];

- (void) pushNextView {
    nextview*s = [[nextview alloc]initWithNibName:@"nextview" bundle:nil];
    s.view.frame = CGRectMake(10, 20, 745, 755);
    //nextview contains the object that I want to pass :object
        s.object= self;
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self];

         [self.navigationController pushViewController:s animated:YES];
        NSLog(@"self.nav%@",self.navigationController);
}
于 2013-05-27T11:55:45.097 回答