Reputation: 49
I have developed login, signup and a couple of other screens for my IOS app. Now I am trying to build the dashboard screen for my app (consider it similar to Facebook's news feed) but facing difficulties creating the UI in the storyboard. Also, if there is no Image in the post then I want the UITableView cell to reduce its size by setting the UIImageView's height to zero, but it's not working for me. Overall for my dashboard screen, I am thinking of building the UI from the code itself. Now I have the following question:
Is it possible to use storyboard for some of the screens and not for others? If yes, then how do I navigate to the screen without storyboard (say my Dashboard screen) from a screen with the storyboard (say my login screen).
Thanks.
Upvotes: 1
Views: 1115
Reputation: 2326
Yes you can make app without using Storyboards or if you want to use you can also use. Advantages of Storyboard
1- Ease of Use
2- Visual
And Advantages of Code
1-Control
2-Reusability
3- Merge Conflict
- This is main reason why some Standard Developers refused to use Storyboard. It is very difficult to resolved the merge conflict. This makes working on the same Storyboard a grueling process. It is not a simple task because our Storyboard merge conflicts consists more than just code, there are codes that renders the UI
.
And Of course you can build App by using both Storyboards and Code.. it totally depends upon you. And for navigation just call simple push and segues method in your code. Hope this helps.
Upvotes: 2
Reputation: 14329
You can mix all types in iOS,
1 . Storyboard
use
let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewController")
navigationController?.pushViewController(vc!, animated: true)
where "ViewController"
is storyboard id
2.XIB
let vc1 = TransHistoryViewController(nibName: "TransHistoryViewController", bundle: nil)
navigationController?.pushViewController(vc1, animated: true)
where "TransHistoryViewController"
is xib name.
3. Programmatically
you have to create UIViewController()
instance & jump there respectively.
Upvotes: 1
Reputation: 702
With storyboard: First embed ViewController into NavigationController
Code for data transfer:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let detailController = segue.destination as? SecondViewController
detailController.object = self.object
}
Without seque:
If both ViewControllers are in same storyboard
func foo() {
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("secondViewController") as? SecondViewController
self.navigationController?.pushViewController(secondViewController!, animated: true)
}
If both SecondViewController is in different storyboard
Get the storyboard from the Bundle then Navigate to it
func foo() {
let fooStoryboard = UIStoryboard.init(name: "Foo", bundle: Bundle.main)
let secondViewController = self.storyboard?.instantiateViewControllerWithIdentifier("secondViewController") as? SecondViewController
self.navigationController?.pushViewController(secondViewController!, animated: true)
}
Without storyboard:
Embed your LoginViewController as rootViewController so that navigation is possible.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let fooStoryboard = UIStoryboard.init(name: "Foo", bundle: Bundle.main)
let loginViewController = fooStoryboard.instantiateViewControllerWithIdentifier("loginViewController") as? LoginViewController
let navigationController = UINavigationController(rootViewController: loginViewController)
self.window?.rootViewController = navigationController
return true
}
Now from LoginViewController you can push programmatically as suggested above.
Upvotes: 2