Looks like duplicate right ??
but i dig the internet and i found nothing ..
please someone help me how to open UIPageViewController on button click
if we want to open uiviewcontroller we can use this
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
self.presentViewController(nextViewController, animated:true, completion:nil)
but what about UiPageViewController ??
how to achieve that ??
You can use a storyboard segue. Make sure that your initial VC is embedded in a NavigationController. Then create a segue from initial to your pageViewController and give it an ID.
Next, in your initial view controller code, instead of instantiate, do push.
self.performSegue(withIdentifier: "seguetoPVC", sender: self)
Put that in your button click and it will allow you to open your PageViewController on button click. Hope this helps.
Related
the thing is im new to ios development this is my second application while working on the first one i mainly used a theme and then worked over it but this one im working from scratch.
My main problem is going from one screen to another
When i use this code it works
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "servicesScreen") as! ServiceViewController
nextViewController.modalPresentationStyle = .fullScreen
self.present(nextViewController, animated:true, completion:nil)
But i need to use this one so i can go back too but this wont do anything
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "servicesScreen") as! ServiceViewController
self.navigationController?.pushViewController(newViewController, animated: true)
My question is, am i doing anything wrong here or do i need to add something in scenedeligate?
try
select Main.storyboard
select initial view Controller
select editor -> Embed in -> navigation controller.
For this, you need to add navigation controller to initial storyboards.
If you are using navigationController you need to add a navigation controller first on storyboard or programmatically.
Programmatically add navigation controller check this link:-
Creating a navigationController programmatically (Swift)
or
To add navigation controller on storyboard you should follow this link:-
https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementNavigation.html
If you have added navigation controller to your app then make sure your intialViewController is set to navigation controller or your navigation controller is added to the stack when you run your application.
Also check for "Is the identifier correct? Did you reference the correct storyboard?".
When I click on the newPostButton, I want to segue programmatically to the NewPostVC (which is that view on the right side).
However, the view does not show up on the simulator, as you can see, it's completely black.
What is the issue, why isn't the view showing up?
And how to fix that?
Thank you guys
If I understand correctly you are trying present view controller on your Navigation stack so you need to do two thing set storyborad ID and set push viewController here is code :
Set 1:
set Storyboard ID : NewPostVC to your NewPostVC Storyborad
Step 2:
#IBAction func newPostClicked(_ sender: UIButton) {
let storyborad = UIStoryboard(name: "Main", bundle: nil)
if let vc = storyborad.instantiateViewController(withIdentifier: "NewPostVC") as? NewPostVC {
self.navigationController?.pushViewController(vc, animated: true)
}
}
I dont know how create segue from storyboard 2 to storyboard 3(image: https://i.stack.imgur.com/NLhJY.png). Afterwards user tap save button(storyboard 2), i need save item and open saved item on storyboard 3. I try use Unwind Segue, but this doesnt work.
I try use instantiateViewController. I set on storyboard 3 Storyboard ID("Item") and then add this code to save button:
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Item") as! ItemViewController
self.present(viewController, animated: false, completion: nil)
But when Storyboard 3 open, after tap Save Button on Storyboard2, navigationbar on Storyboard 3 doesnt showed. Anyone can help find me solution to this problem?
You need to specify which storyboard you want to use exactly along with your ViewController identifier.
Try this:
let storyboard: UIStoryboard = UIStoryboard(name: "YOUR_OTHER_STORYBOARD_NAME", bundle: nil)
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "Item") as! ItemViewController
self.show(viewController, sender: self)
In my app I use side bar as in facebook. when the user slides out the side bar a uiimageview is displayed. when user taps on the image it takes hm to a different viewcontroller. the problem i am facing is that I have created sidebar programatically and the other view to which I want to navigate the user is created using storyboard. So my source view is created programatically and destination view is created using storyboard. So can someone explain me if there is any way of using "Segue" in this scenario. Since i can not create segue using storyboard I need to do it programatically but even after a lot of googling i could not find the answer.
Well, to get another instance of another storyboard programmatically you can use something like:
let newController = UIStoryboard(name: "MyStoryboard", bundle: nil).instantiateViewControllerWithIdentifier("MyIdentifier") as! MyViewController
and then you push to your navigation controller, or add as a child view controller or something...
If you don't wanna bother with identifiers you can just use the instantiateInitialViewController instead of instantiateViewControllerWithIdentifier
Might help
"userSB" is the viewcontroller storyboard identifier
#IBAction func tapSearchCriteria(_ sender: Any?) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let aVC = storyboard.instantiateViewController(withIdentifier: "userSB") as? AViewController
aVC?.modalPresentationStyle = UIModalPresentationStyle.custom
aVC?.transitioningDelegate = self
aVC?.udelegate = self
self.present(aVC!, animated: true, completion: nil)
}
I have a TapBarViewController with three Taps in my project.
Now I am trying to put a normal FirstViewController in front of the TapBar ViewController when the application launches.
The FirstViewController should have three buttons for one of the individual Taps of the TapBarViewController.
How can I show the individual Taps of the TapBarViewController by pressing one of the three buttons?
Screenshot
This is the exact answer you are looking for.
Steps:
Add a UIViewcontroller and embed with UINavigationViewController (Editor -> EmbedIn -> NavigationController).
Add Three button + 1 Button (Navigate to TabViewController).
Drag and drop UITabBarController to the storyboard it comes with one default ViewController and place a UILabel named as 'ButtonOneClicked'.
Create Two more ViewControllers and named as 'ButtonTwoClicked' and 'ButtonThreeClicked'.
Connect 'ButtonOne' with FirstViewController and set segue as Show and repeat the same for rest two.
Click on each segue and provide an unique Identifier name.
Then connect the UITabBarController with each UIViewController and choose viewcontrollers
Create a ButtonAction to the Tab Button.
Copy paste the below code in that action.
#IBAction func tabClicked(_ sender: Any) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "Tab") as! UITabBarController
appDelegate.window?.rootViewController = initialViewController
appDelegate.window?.makeKeyAndVisible()}
Hope this helps you!!