Camus
Camus

Reputation: 845

Best practise in creating an uiview and presenting them in iOs

Is it a good practise to creates views in xcode and hide them and when required show them?

I am asking that because I prefer to create views visually and not in code.

If the view is to complex(a lot of subviews) should I create a new view controller to it?

I know there isn't a specify question here but I really need a clarification on this matter.

Regards

Upvotes: 1

Views: 206

Answers (3)

Bishal Ghimire
Bishal Ghimire

Reputation: 2610

UIView is the best way to create iOS app, esp. if you want to reuse the code. For example if you have same view to present in iPad n iPhone then using UIView can result in lots of similar code in View-controller In another case if your view might need to have multiple table view it can be quite complex to handle each with delegates in ViewController. But separate view will solve this problem.

I have made my 1st open source code after learning how to use View https://github.com/bishalg/BGRadioList

which I had learned from http://www.raywenderlich.com/1768/uiview-tutorial-for-ios-how-to-make-a-custom-uiview-in-ios-5-a-5-star-rating-view

About the hiding view - I have used lots of hide and show view codes in my apps but believe me at one point it will become complex and unmanageable if you have lots of views.

Upvotes: 0

alex
alex

Reputation: 2131

As for me, I prefer folowing practice:

Usually, a use storyboards,where views are placed, but if a view is complex, I create a separate XIB file, arrange all subviews there, and then in storyboard drag an UIView subclass and connect my XIB view with it.It helps to avoid mess in storyboard.

As for hiding views, I also don't recommend such practice as it can become very complex to understand your code and all those views are allocated when XIB is loaded, so the mobile developing rule "do as lazy as u can" is not met. We should try to spend as less memory as it's possible.

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 993951

One of my first iOS applications had a tab bar and views that the user could switch between. Originally it was done by hiding and showing the right views depending on what the user pressed on the tab bar. This ended up being a complex disaster.

I then rewrote the app so that each tab bar view had its own UIViewController with its own set of views. That turned out to be so much easier to manage. (I also changed from using Interface Builder to straight code for creating the views, but that's beside the point and you can continue to use IB if you want.)

Upvotes: 2

Related Questions