嗨,你可以试试这个
[self dismissViewControllerAnimated:YES completion:^{
//code to be executed with the dismissal is completed
// for example, presenting a vc or performing a segue
}];
您可以在完成关闭一个视图控制器后编写代码
或者您可以在解除方法的一些延迟后通过当前视图来实现这一点
-(void)onDismisViewController{
[self performSelector:@selector(presentSecoundViecontoller) withObject:self afterDelay:1];
}
-(void)presentSecoundViecontoller
{
SecoundViewController *secoundVC = [[SecoundViewController alloc] initWithNibName:@"secoundVC" bundle:nil];
[self.navigationController presentViewController:secoundVC animated:YES completion:NULL];
}
编辑
试试这个我试试它的工作
在 subviewcontroller1 中创建一个委托方法并在 mainviewcontroller 中设置委托并在 mainvie 中实现方法并在此委托方法中呈现 subviewcontroller2 其工作
试试这个,如果不让我知道会发布代码。
在 subviewcontroller1.h 文件上创建委托
@protocol st1Protocol <NSObject>
- (void)presentViewController;
@end
@interface SubViewController1 : UIViewController
@property (nonatomic,assign) id <st1Protocol> delegate;
- (IBAction)dissmiss:(id)sender;
SubViewcontroller1.m 文件
我将关闭视图放在 subviewcontroller1 的按钮单击上,您在关闭方法中执行此操作
- (IBAction)dissmiss:(id)sender {
[self dismissViewControllerAnimated:YES completion:^{
//code to be executed with the dismissal is completed
// for example, presenting a vc or performing a segue
[self.delegate presentViewController];
}];
}
现在在主视图控制器中实现这个委托方法。在 .h 文件中实现委托方法
@interface StViewController : UIViewController<st1Protocol>
在 mainviewcontroller.m 文件视图中设置委托
- (void)viewDidLoad
{
[super viewDidLoad];
subViewcontroller1 *st1=[[subViewcontroller1 alloc]initWithNibName:@"subViewcontroller1" bundle:nil];
st1.delegate=self;
[self presentViewController:st1 animated:YES completion:nil];
// Do any additional setup after loading the view from its nib.
}
主视图控制器中的委托方法实现
-(void)presentViewController{
SubmViewcontroller2 *st2=[[SubmViewcontroller2 alloc]initWithNibName:@"St2ViewController" bundle:nil];
[self presentViewController:st2 animated:YES completion:nil];
}
希望这可以帮助您快乐编码。