Right way to create a reusable component in iOS - ios

I have a button and a related view which needs to be embedded in different ViewControllers in an iOS App. What is the recommended way of creating it? Should I create a ViewController with different views and use them in the components? Any pointers appreciated.

Related

Best approach for 1 screen contains 2 view controller

I want to learn parent - child concepts in iOS. I found a some app in app store and I liked the their design. They have 3 button in same view controller when the user taps a button below view changes and calls their view controllers. Like a TabBar.
I tried to create 3 xib files. When the user taps the buttons they are awaking from nib and I added them to my containerView subview. It works. But I couldn't send a data between them because there is no prepare for segue method to so i couldn't prepared them.
I tried to create 3 viewController in Storyboard and I use them with the Storyboard ID. It works. But still can't transfer data between them.
I didn't understand what is the best approach for solve this problem ? I researched on the web about Custom Segues and Parent - Child concepts but I couldn't find anything.
What is the best approach for make a container like in the image ?
Thank you.
I am not sure if there is something like a best approach, at least in general term. It really depends on your specific demands and other logic of your app.
Both creating XIB files and creating ViewControllers in Storyboard together with their ID is ok. Here it is more about your preferred way. I would say that today you will probably see more using Storyboard than XIB files.
In terms of data transition. There are several ways, if it is not some very heavy logic then delegates can do it pretty well and easy.

iOS PageViewController with different page layouts using storyboard

I am trying to use the PageViewController with different layouts but I dont know how to accomplish that. Currently Im using the page-based application provided as a template for new projects in XCode 5 for iOS. This application uses the same view controller for all pages, and I want different pages. Is this even possible? And how can I add a different view while using this template and storyboard. I couldnt find any tutorials that uses storyboard and adding different pages.
I have also tried UIScrollView with paging enable. But those tutorials I found required to turn off auto layout in settings, such as this one:
http://www.iosdevnotes.com/2011/03/uiscrollview-paging/. And that is not the correct way of doing it.
Since I havent found any examples, I start to wonder if this is even possible to do in a simple way?
I don't think this is possible using storyboards in the straightforward way you want, but it can be achieved with relative ease. You can create all your different view controllers in the storyboard (these will serve as pages) and give them identifiers. Now in code, have the view controller that displays the page view controller be its data source.
Now, in – pageViewController:viewControllerBeforeViewController: and – pageViewController:viewControllerAfterViewController:, implement logic that decides which view controller to load, and use the storyboard's – instantiateViewControllerWithIdentifier: to return an appropriate view controller.

Convert a Single View to Tabbed App in iOS/Xcode

I have a few simple apps that are single view. I want to add a 'Info' tab for some instructions, support details, etc.
What is the easiest way to do this? Create new Tabbed Apps and copy the existing code in, or edit the current single view apps? I would prefer if the latter was possible.
Thanks.
I achieved the same in <5 seconds with the below xCode menu option: Tab Bar Controller.
I kept my ViewController classes so my main.storyboard looked like this:
Without understanding more about your current setup your question can't really be answered with any kind of accuracy.
Having said that it's easy enough to add a UITabBarController to an existing app, really all you need to do is change the initial view controller.
I presume you haven't tried searching for an example...
Implementing UITabBarController in code: http://simplecode.me/2011/12/05/tab-based-ios-apps-uitabbarcontroller/
Storyboards: http://mobile.tutsplus.com/tutorials/iphone/ios-quick-tip-creating-a-uitabbar-application-with-storyboards/

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
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.)
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.
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.

UIViewController or UIView? Or even a better design solution?

I have a problem of designing an app. That's why I like to discuss it with you guys.
This app should be like a dashboard. You have several small windows/widgets that are filled with different data (images, tables, etc...) It is possible to add more widgets or remove them. Drag and drop aren't allowed.
What I am not sure about is designing it in the right way.
I will create one WidgetViewController for the widgets. So everything is kept encapsulated.
Then I will put all views in one "parent" UIViewController to use it with UIPagecontrol.
Is this a common way to have multiple UIVIewControllers in one UIViewController at all? I am not sure if this works anyway.
Or just create a class inherited from UIView?
You can have a container viewcontroller with uipagecontrol and uiscrollview that holds your widgets just like the weather app in ios.Depending on the different widgets you need to implement different viewcontrollers and add their views to scrollview.If you do not implement different view controller you might have difficulties handling your subviews since you need to control your views from a single view controller.

Resources