公告
财富商城
积分规则
提问
发文
2019-01-10 08:02发布
再贱就再见
Have been struggling with this for a while, and can never seem to get a direct answer.
Any help is appreciated!
I think the OP is asking how to swap a VIEW without changing viewCONTROLLERs. Am I misunderstanding his question?
In pseudocode, he wants to do:
let myController = instantiate(someParentController)
let view1 = Bundle.main.loadNib(....) as... blah myController.setThisViewTo( view1 )
let view2 = Bundle.main.loadNib(....) as... blah myController.setThisViewTo( view2 )
Am I getting his question wrong?
This worked for me:
NSTimer *switchTo = [NSTimer scheduledTimerWithTimeInterval:0.1 target:selfselector:@selector(switchToTimer)userInfo:nil repeats:NO]; - (void) switchToTimer { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"MyViewControllerID"]; // Storyboard ID [self presentViewController:vc animated:FALSE completion:nil]; }
Swift 3.0 in
one view controller to secondviewcontroller go:
let loginVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MsgViewController") as! MsgViewController self.navigationController?.pushViewController(loginVC, animated: true)
2nd viewcontroller to 1stviewcontroller(back)for: back button on action event:-
self.navigationController?.popViewController(animated:true)
3rdviewcontroller to 1st viewcontroller jump for
self.navigationController?.popToRootViewController(animated:true)
and most important storyboard in navigation bar unclicked make sure than this back action perform
To dismiss the Viewcontroller called with the previous answers code by CmdSft
ViewController *viewController = [[ViewController alloc] init]; [self presentViewController:viewController animated:YES completion:nil];
you can use
[self dismissViewControllerAnimated:YES completion: nil];
The instantiateViewControllerWithIdentifier is the Storyboard ID.
instantiateViewControllerWithIdentifier
Storyboard ID
NextViewController *NVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NextViewController"]; [self presentViewController:NVC animated:YES completion:nil];
If you want to present a new view in the same storyboard,
In CurrentViewController.m,
#import "YourViewController.h" UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; YourViewController *viewController = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifier"]; [self presentViewController:viewController animated:YES completion:nil];
To set identifier to a view controller, Open MainStoryBoard.storyboard. Select YourViewController View-> Utilities -> ShowIdentityInspector. There you can specify the identifier.
最多设置5个标签!
I think the OP is asking how to swap a VIEW without changing viewCONTROLLERs. Am I misunderstanding his question?
In pseudocode, he wants to do:
let myController = instantiate(someParentController)
let view1 = Bundle.main.loadNib(....) as... blah myController.setThisViewTo( view1 )
let view2 = Bundle.main.loadNib(....) as... blah myController.setThisViewTo( view2 )
Am I getting his question wrong?
This worked for me:
Swift 3.0 in
one view controller to secondviewcontroller go:
2nd viewcontroller to 1stviewcontroller(back)for: back button on action event:-
3rdviewcontroller to 1st viewcontroller jump for
and most important storyboard in navigation bar unclicked make sure than this back action perform
To dismiss the Viewcontroller called with the previous answers code by CmdSft
you can use
The
instantiateViewControllerWithIdentifier
is theStoryboard ID
.If you want to present a new view in the same storyboard,
In CurrentViewController.m,
To set identifier to a view controller, Open MainStoryBoard.storyboard. Select YourViewController View-> Utilities -> ShowIdentityInspector. There you can specify the identifier.