Single Storyboard vs Multiple Stoaryboard in XCode, which one is better - ios

Is Multiple Storyboard in single project is better than single storyboard??if yes then why??
Which is better Single Storyboard or Multiple Storyboard??
Any one please clear me the above queries.

It depends on the project requirement. If you are good enough with the size classes and auto-layout and also if the requirement flow is almost similar for all the devices then go with single storyboard.
By default in Xcode 6 or later, recommending to use single storyBoard.

If you have a bigger app and/or not only one man team:
You should NOT use single story board. Like its name says, it is a "STORY" board. You should have one Story in one Board. This keeps the readability and maintainability of the storyboard.
If you have a team, it is a nightmare to "merge" one single story board if 2 made changes in it at the same time. It is more or less impossible. But if you have for each story a corresponding storyboard, even in a scrum team you can manage to work on one storyboard only one person, that you do not need merging.
There are a lot usefull documents and workshops in internet if you google "ios storyboard git merge ...."

When to Use Storyboards
Finally, while Storyboards are best used for scenarios involving multiple view controllers, it’s also defensible to use a Storyboard when working with a single table view controller for three reasons:
The ability to design table cell prototypes in-place helps keep the pieces together.
Multiple cell templates can be designed inside the parent table view controller.
It’s possible to create static table views (a long awaited addition that’s unfortunately only available in Storyboards).
When Not to Use iOS Storyboards
A few cases:
The view has a complicated or dynamic layout, best-implemented with code.
The view is already implemented with NIBs or code.
When to Use NIBs for iOS UI Design
A subset of all uses cases would be:
Modal views
Simple login and registration views
Settings
Popup windows
Reusable view templates
Reusable table cell templates
Meanwhile…
When Not to Use NIBs
You should avoid using NIBs for:
Views with dynamic content, where the layout changes significantly depending on content.
Views that by nature are not easily designable in the Interface Builder.
View controllers with complicated transitions that could be simplified with Storyboarding.

Apple's docs say that you may have multiple storyboards. Unfortunately they don't go into any real detail on how to do that. As you've found out, Interface Builder won't help you, so you'll have to do it in code. It works much like loading XIBs:
[UIStoryboard storyboardWithName:#”MyNewStoryboard” bundle:myBundle]
Having said that, if you don't "want one big/bloated storyboard" as then XIBs really are the way to go. That 'bigness' is the benefit: all the transitions between VCs are laid out in one place. Having multiple storyboards is really so that you can support multiple different and unrelated flows through your app: for example, one storyboard for a complex configuration flow and another one for the main user flow.

Related

Storyboard is very slow

So I've been working on a project for a while that has so many view controllers, but I notice that now when I try to do a single edit in any view , storyboard hangs, or become unresponsive . what would be the solution for this issue ? is it possible at my current state to split up the whole storyboard into smaller ones ? and will that resolve the problem ? I'm using Xcode 9.3
Yes. You can have more than one storyboards in one project. In fact that's the preferred way to manage very large projects. To create more storyboards go to File Menu > New > File... and then select Storyboard from the User Interface section. Doing this should resolve your issue. However, if the issue still persist you can consider taking out the specific user interface into its own .xib file.
Update:
If I were in your position I would have considered using .xib files to create my user interface instead of using storyboards. Storyboards do have their advantages but there are some cons too if you use them. Like:
If you work in a team you will run into merge conflicts more often because someone else made a change in the storyboard.
I am still not a Guru in S/W design but, to me it seems like Storyboards violate the Single Responsibility Principle of S/W design.
You won't be using Segues in complex ui flows anyways so what's the point of having every thing in one file.
You won't be able to reuse your UITableViewCells interface. Prototype Cells are a good idea but if you have a UITableViewCell which is used in more than one UITableView you will have to replicate the UI in Storyboard.
In my experience, in a more complex and large project having everything in one Storyboard makes it even hard to comprehend the UI/UX flows as Segues from every view controller seem to connect with every other view controller to the point where it just stops making sense at all.
Yes, it is best practise to distribute viewConrollers into multiple storyboards so that you can open it quickly but it can lead your time to manage each storyboard identification programatically while accessing into code.
Otherwise, you can set storyboard View as : iPhone 5C so that it can load little bit faster than bigger devices.
Refer:

Use storyboard or xib for single view controller?

I have to implement the layout of a single screen, which is not connected to the overall app flow, and I was wondering if it makes sense to use a Storyboard.
Storyboards make sense for flow/navigation (multiple controller), have some convenient features like, iirc prototype cells which are not available in xib. And it also makes sense if I think maybe later the screen may become a "story" (more view controllers). But none of this advantages are useful for my particular case.
I was thinking anyways in using Storyboard, as it seems to be a bit more flexible than xib generally, but is there any disadvantage? Maybe performance penalty or such? Is there a preferred way to setup single view controller?
Go ahead..take the advantages of using storyboard. There is no disadvantages or performance issues particular to storyboards when compared to xib files. Its all about your convenience. As you said the single view controller may become a story in future, then the storyboard would be a right decision. And when to use xib? thats upto you, one ideal situation where i will choose xib is, if i have an independent controller that i want to share with other project also then i would choose xib.
The performance penalty would only bother under the circumstance which too many controllers (more than 10) with segues were squeezed in one Storyboard. Everything would be totally fine before that.
And if you have more than two people are trying to edit same storyboard file than you have to resolve conflict, which will be more tedious job.
Storyboard benefits:
a. easy demo purpose and fast implementation.
b. small team like two person.
c. Storyboard is providing complete view and navigation model.
XIB benefits:
a. You can modularize your code.
b. More people can work on different-different controller without affecting your xib or code.

Show/Hide UI elements in a storyboard depending on the target

I have read a lot about creating a lite and a paid version with Xcode and in my app I am using multiple targets and preprocessor macros as described in this Stackoverflow post. However, I don't know how to handle different targets with a Storyboard.
For example, in my storyboard I have a table view controller with static cells. In the paid version it has four cells, in the lite version has one extra cell whereas the rest of the storyboard remains unchanged. Is there a way to achieve that kind of behavior?
(Creating a new storyboard for the lite version (or duplicating it) is not an option for me as I have dozens of view controllers and 98% of the views and UI elements are identical in both versions. It would make the project difficult to maintain.)
For example, in my storyboard I have a table view controller with static cells. In the paid version it has four cells, in the lite version has one extra cell whereas the rest of the storyboard remains unchanged. Is there a way to achieve that kind of behavior?
If you hadn't boxed yourself in by using a static table, this problem wouldn't have arisen in the first place; you'd be configuring the table in code, which can be conditional — end of issue.
As things stand, you'll need two different scenes in the storyboard, one for the paid version, the other for the lite version. Then:
If this scene is reached by a segue, you'll need two different segues that reach this scene, and you'll decide in code which one to trigger (and trigger it in code, not automatically).
If this scene is the initial view controller, you'll need to instantiate it initially in code rather than letting UIApplicationMain do this for you. Or, in that case, use two different storyboards for just this one scene, and then segue to another storyboard.
(And do keep in mind that multiple storyboards are a great way to organize your scenes in any case. I don't necessarily mean multiple alternative storyboards; multiple sequential storyboards can keep your storyboard from becoming overly complex. It sounds to me from your question as if all you need to do is understand how storyboards work - they are not magic, you know - and be more nimble in your use of them. Your entire deer-in-the-headlights fear of duplicating your storyboard - "I have dozens of view controllers" - suggests you've already gone way too far down the wrong road. Programming is like solving a Rubik's Cube: if you're in the middle of it and your response to someone trying to change something is "don't touch it!", you're doing it wrong.)

XIB over Storyboard [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Currently we use Storyboard over xib in all projects. But in my view if you want to make reusable view (custom view or Tableview cell) which can be re-used in different view controllers, you must use xib files as in storyboard there is no way we can make single view object separately.
Note that I am using Storyboard for workflow (view controllers with segues all around) of entire application. Only for reusable tableview cells I am using XIB.
I have searched in lot of apple documents as well as WWDC videos but I could not find any concrete proof from Apple developers which says that XIBs are here to stay or you should use XIB for custom views.
If any of you guys have any kind of links which gives somewhat confidence that we can still use XIB without fear of apple removing it, it would really be appreciated.
Storyboards are recommended when you don't reuse views.
Once you want to reuse something in multiple views/storyboards, then you need XIBs. You already mentioned the example of custom cells. That is something I need quite often and I want to use the same cell in multiple table views. I do the same with charts. I create a chart view in which I set colors etc. and I reuse it everywhere, only putting different data in it. This saves me a lot of code in respect to style/appearance and makes the app easily maintainable. In case of change (e.g. because of new iOS version), I need to change everything on a single place.
Furthermore, I want to have views (e.g. cells) for iPhone and iPad and let the system determine which one to use. For this, again, I need XIBs. I use the notation with ~iphone or ~ipad at the end and I don't have to write code for retrieving the correct view.
This are two things that you simply cannot do without XIBs. So, following the Apple guidelines, my approach is to use storyboards whenever possible and XIBs only when I need them (mainly because of reusability). But there are real cases when one needs XIBs! Simply ignoring them is not a good practice for sure. Actually, in each project I have storyboards as well as XIBs.
Edit: I just found a great post explaining the disadvantages of storyboards. There are plenty of things that I was not aware of.
Also, you don't have to use either exclusively. You can still use XIB files even if most of your work is in storyboard. And using either also doesn't restrict you from creating a view that isn't built in IB at all.
Storyboard has plenty, plenty of advantages. Particularly when you start bringing new people in on the project. Without getting engulfed looking at hundreds of thousands of lines of code, a new developer can look at the storyboard and in 30 minutes or less get a quite good idea of the flow of the app.
With that said, you should never limit yourself to anything. Limiting yourself to just storyboard and never using XIB or building a view completely in code is like saying "We're only going to use NSArrays, and never NSDictionary or NSSet". Instead of a silly limitation, you should always just be sure you're using the right tool for the job.
My opinion is use which one is appropriate for that context, here is some guidelines:
When to use nibs
Modularity is key to well designed nib files
Use nibs to store views, subviews, custom controls or repeated views
There’s no way to represent the relationship between screens of related content
When to use Storyboards
Storyboards are best used to represent screens of content and the connections between those screens
Give due care and attention to the prepareForSegue:sender: method
Modularity is still applicable when designing storyboards
General Guidlines
Decompose your projects into nibs and storyboards
Views, subviews and custom controls should be contained within separate nib files
Use storyboards when designing full screen content and there are clear relationships between scenes
Consider whether the interface needs to be static or dynamic
Use separate storyboards to encapsulate reusable sequences of scenes
Use separate storyboards for unrelated scenes
Table view cells that can be reused across different controllers belong in nib files

How to manage the development of storyboard when several people edit the storyboard?

All of our views are in a single storyboard. After we edit the interfaces we are responsible for, we find it is a disaster when we commit the storyboard. Do any better ways exist that make it easier to manage the storyBoard? Should we write UI with code instead of storyboard or xib? While it is really efficient to use storyboard.
What's generally worked for me and my team is to separate related functionality into different storyboards. So if one person is working on x portion of the app, stick all things x related there. As long as only one person is dealing with each component at a time, there's no chance for conflicts that blow up your whole storyboard.
Another thing to keep in mind if you can only use one storyboard, is to limit who can work on each ViewController in the storyboard. It's not the best idea to have multiple people working on the same controller anyways, since you will both be interfering with each others layout. I have found that as long as we stick to our own components, merges are super easy.
Your solution of using code instead of storyboard is also a very valid way to go about it. The decision between code and xib based approaches depends on the user. Code takes longer to get going, but is super easy to reuse, whereas xibs/storyboards make prototyping a snap but are very hard to reuse.
You need to read this links:
http://blog.waynehartman.com/archive/2012/01/07/uistoryboard-on-ios-5-the-good-the-bad-and-the.aspx
http://www.linkedin.com/groups/Which-is-better-StoryBoard-NIB-162305.S.185584395
Should I use storyboard and mercurial for team work?
Storyboard is one single file, so only one person can work on the storyboard at once. It is essential factor for working with team in iOS.
The following post helped me to understand answer on this question:
http://robsprogramknowledge.blogspot.pt/2012/01/uistoryboard-best-practices.html

Resources