Tofik Tamboli
Tofik Tamboli

Reputation: 27

Is creating a lot of UIViews in UIViewController a good practice for storyboards? Does it have any impact on application like memory?

Today I heard about new approach of design views in storyboard

Lets consider one page contain image , label and button now out storyboard as follow

1] our one UIViewController divides in three part i.e 3 UIViews for 3 components like one UIView for image
2] for keep image responsive take another UIView and keep imageView inside that and then set constraints and keep wight and height of imageView aspect ratio.
3] I given different colour for different UIViews for understanding final hierarchy is as below

enter image description here

So as per screenshot you can see view are more responsive and changes made in one UIView is not reflect is another one and our hierarchy of view are maintained .

Finally come to the questions
1] is this approach correct?
2] is there any impact of this much UIView views on application in terms of memory and performance?

Upvotes: 1

Views: 111

Answers (2)

Tofik Tamboli
Tofik Tamboli

Reputation: 27

I tried this method a lot and I realise this approach solve lot of problems of setting constraints. This approach is similar as Bootstrsp . We are going to divide hole screen by UIViews and Finally put our main design views in it. Till now I don't know what is bad impact of this approach in application in terms of memory and speed. That I will explain in future.

Thanks a lot.

Upvotes: 0

Lukáš Mareda
Lukáš Mareda

Reputation: 341

Answer on first question:

The approach how to handling lot of views? No it is not correct. If you had lot of views in scrollView use UITableView or UICollectionView, because of better handling, reusing and layouting - features provided by UIKit for free. If you have lot of views on one screen without scrolling - try to use UIStackView - it will provide you lot of automatic layouting and very easy editing and updating layouts instead of using autolayout / layout masks. UIStackView can be considered as AutoLayout generator machine.

Answer on second question:

No. Using large storyboards has no much bigger impact on memory and performance, than generating it via code.

There is two main problems with storyboards:

1) Large storyboard has performance impact on XCode. Especially with older Macs.

2) If two or more people working in one storyboard simultaneously, you need to be aware, not to edit same ViewController together, or creating new, otherwise you will have repository conflicts (same as 2 persons edit same piece of code at same time), but you have to resolve it in xml, what is readable, but it takes some time to understand.

Upvotes: 0

Related Questions