我在推送viewcontroller方面遇到了问题。这就是我做的:点击一个按钮,我使用这段代码添加一个模态视图我就可以了:
- (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);
}
这个添加的viewcontroller包含一个完成按钮,我想用它来导航到其他viewcontroller:所以我使用那个代码但它不起作用,它只是忽略了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);
}
答案 0 :(得分:0)
视图控制器的self.navigationController(以模态方式呈现)将为nil
并且您无法注意到这一点,因为您正在分配导航控制器对象。
答案 1 :(得分:-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);
}