Issues with .xib files - ios

So I've "accidentally" created 3 nib files, I can swipe right and left between three views (.xib files) however, I have some issues regarding the layouts and auto-layouts, for one device it looks great, the others.... not so hot.
I'm trying to add a few images and a button, however, the placement is totally weird.
How can I address this issue?
Also, could I just use a ViewController to present itself over the .xib file if possible?

There are two ways you can consider on your situation.
Firstly, You can connect each of these 3 nib files with a view controller. Then you can use a page view controller to manage all these three view controllers. Page view controller supports swipe right and left for showing different view controllers. You only need to make each view controller layout correct then all the swipe actions will be handled by page view controller.
Secondly, you can create a root view controller with 3 sub view controllers. You should call rootViewController.addChildController method to add these 3 sub view controllers. But you need to be carefully about the layout of these 3 sub view controllers since they are only part of the root view controller.

You have to check auto layout constraints for your display issue. Some times auto layout leads problem for your display.
And for three .nib files you can simple use view controller and add it to the root view when you need it and remove it from root view when you want to remove it.

Related

Container controller view sizing

I'm currently building a custom view controller container for my iOS project and I nearly understand what I'm doing. The one thing I'm stuck on is how do you (properly - aka not a hack) add a view controller in PART of the Parent controller's frame. See how there are multiple view controllers/views in the email app? How does one build a custom controller container that designates the location of such sub-view controllers? How do you properly add such a controller? I'd like to know the "correct" way as designated by apple (best practice).
EDIT: After looking at this some more I was thinking a possible way would be to create views with custom sizing and then push those to the parent. Is this the correct way?
You sort of answered it yourself. The view you have as an example uses a UISplitViewController to show two separate views (left and right). Each of those views has a view controller that owns it. Note that the left side includes all of the view, like the search, nav bar, and toolbar. So just create two separate view controllers and add them to a UISplitViewController and you should be golden! The views themselves are created however you normally create views. Storyboards, NIBs, or in code works.

Best practice to develop common header view across all controllers/windows in iOS app

I'm keeping on developing an iPhone app (rigth now native one) and I would need to use a common "header" for all views but I don't want/need a UINavigationBar and prefer much more have a common "partial view". It will have some actions to perform but always the same ones (showing notifications panel, basically). It should be something like you can see in the screenshots.
I don't need (I feel) delegation because the controller's view can handle notifications and show them when user clicked the customize button.
I don't mind to use a Nib o make the view hardcoded but I'm not sure how I must make an instance of the view or the controller that handles it within each app tab (I'm using UITabBar as navigation control).
From my point of view it doesn't exist a way to get a common controller to call wherever needed; you just can use some method to present new controller as modal o push it out and I think that is not what I'm looking for.
Any idea is welcome. Thanks
Create a custom view controller with 2 subviews. Subview 1 is the header. Subview 2 is the container view where child view controllers are displayed (your tab bar controller in this case).
Your custom view controller could be the delegate of the tab bar controller if you want, so it can be notified when the tabs change and update anything on the header view.
Well, finally is have used the solution I found on the link http://patientprogrammer.wordpress.com/2012/03/12/re-usable-subviews-in-ios/
I have created a Nib with a view controller and then, in the main window I have added two view, the top one subclasses the view controller for the Nib view and it is rendered automatically when app is launched without a single line of code within "main" controller. See the screenshots for more detail:
Thank you very much for your help

Adding a split view controller to a single view project in Xcode 5

I have an application that is working quite well, but the customer wants to combine two of the views (UIViewControllers) in to a single view (a Split View Controller).
The master part of the view will be a table with a list of Staff in a TableView, and the detail view will be made up of two Table Views - one that contains details about the member of staff (name, phone, ext, office etc) and the other with training records (courses, qualifications and so forth).
When you click on the master table, it selects the detail records for the given member of staff and displays them in the detail view.
I have no storyboard in the application, and use [self presentViewContoller] to switch from view to view (because there is a lot of conditional processing on what view is required and a storyboard seemed to be too restrictive)
However I have tried the following :-
Creating a SplitViewController (right click, New File, UISplitViewController), but it seems to be empty with no master or detail views. Also, when I try to make it appear, it either doesn't appear, or causes it to crash (tried to present a SplitViewController modally).
Creating a "fake" split view controller, by putting two views on a normal view controller, then putting the required tables inside them. However I can not find a way to present any borders or the like, and the whole thing looks a tad unprofessional and stupid.
So my question is basically this :-
Is it possible to create SplitViewControllers in single view projects, and use them?
Or, if not, is it possible to put borders around views, or tables, or draw a single straight line on a view?
(If at all possible, I would prefer not to have to rewrite my entire application and just add this SplitView controller or the "fake split view Controller")
You can use container views:
Create a new root view controller and add two container views to it. This will create two embed segues that you can point to the view controller's whose views you want to appear in these containers.
You cannot control two UIViewController simultaneously.
So, try displaying two UIView or subclasses of UIView like UITableView.
Displaying Two UITableView is a little tiresome.
Take a look at this question Two UITableView in the same view
As for borders around views, you can put UIImageView or something as border lines.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(159, 0, 2, 640)];

Put two UIViewControllers on screen side by side

On iPad, I've got a main UIViewController that's supposed to embed side by side two childViewControllers. How can I instantiate them both, and put them on screen?
You can use container views in IB. Drag out 2 container views into the controllers view, and size them how you want. You will automatically get two connected view controllers, sized appropriately. The main view controller, and its two children will all be instantiated at the same time. If you need to get access to the children from the parent, you use self.childViewControllers.
Sounds like you should use a UISplitViewController as a container for two view controllers:
The UISplitViewController class is a container view controller that
manages the presentation of two side-by-side view controllers.

accessing 2 viewControllers

I am creating an ipad application, I two view controllers the size screen of an iphone 5 and I would like to show both of them on the ipad screen, as two distinct UIViewControllers though. Is there a way to do it?
I have tried to alloc the second viewcnotrller in the viewdidload of the first, but what I notice is that it alloc the first and the second, but the first is not accessible any more (it looks just like a still image).
You can do it very easily in the storyboard. Just add 2 container views (next to the regular UIViews in the object list) to your controller's view, and size them how you want. You will automatically get 2 view controllers connected to the container views by an embed segue. Just change the class of these 2 controllers to your custom classes, and you should be good to go. If you need to get a reference to these controllers from the main controller, you can get it from the childViewControllers property. Your main controller (assuming it's the initial controller) and the 2 child controllers will all be instantiated at start up with no code necessary.
Check out view controller containment, in which you have a container view controller, which then can load one or more children view controllers. Also see the relevant section in the View Controller Programming Guide. Also see the WWDC 2011 session, Implementing UIViewController Containment.

Resources