Universal app design 1 table view that opens different view on cell click depending if on iPad or iPhone - iphone

I'm making a universal app and I've run across a situation I'm stumped on. On the iPad I'm using a split view, and I would like to make a UITableViewController that is shared on both the iPad and iPhone. I did that, but now when the user clicks a table cell I need to respond. On the iPhone I will init a new view controller and push it in the UINavigationController stack, but on the iPad I will init a different UIViewController and display it in the detail view pane. I know how to do each of these actions by its self, but how do I write the UITableViewController so that it knows which action to preform depending if its the iPhone or iPad?
Is there a better way to handle this?

Here's what I did in that exact same situation.
The table-view controller had a property called detailViewController. If this property is not nil than I updated that view based on what cell was touched. If that property was nil I must be on the iPhone and inside a UINavigationViewController. I use self.navigationController to push my new iPhone view.

Related

UITableViewCell in iPad master detail UISplitView does not automatically respond to orientation changes

In xcode 4.2, if you set up a new project for both iPhone and iPad and choose to create a new iOS "Master-Detail Application" Xcode will set up a lot of template code for you. The iOS "version" of the application has a different simpler storyboard. I want the detail view of my application to also be a Table View controlled by a table controller and I want the cells of this table view to automatically resize with an orientation change. The problem is that while this works for the iPhone version of the application, it doesn't work for the iPad version.
Pre-conditions:
If you edit the detail view on the iPhone storyboard so that it contains a Table View Controller and define the table view to contain a single prototype cell - set the prototype cell to be of a custom type and add some subviews to it then define those subviews with auto resize properties (for example two buttons - one fixed to the left side of the view, the other to the right margin of the view). Do the same for detail view of the iPad storyboard (which of course is contained in a more complex split view controller arrangement).
Double check all the view controllers have resize view from NIB selected (which they do by default) and all the views have Autoresize Subviews selected.
Expected:
When the application is compiled for either iPhone or iPad, in both cases the table cell and it's subviews should resize on orientation change.
Actual Result:
On the iPad version of the app the table cell does not re-layout to match the changed size of the UITable view. The table cell on the iPhone version of the app behaves as expected.
It's clear the chain of subview layout for nested views is broken such that re-layout subviews is not occurring or getting called all the way down to the table view cell when an orientation change occurs. Anyone know if this can be fixed in Interface Builder or if not what code is required to re-establish the chain? I know how I can fix this using willRotateToInterfaceOrientation:duration: , in my own custom subclass of UITableViewController but I'm not sure doing it this way is clean and I would prefer not to have partial automation of orientation changes with scraps of code providing workarounds for stuff I think it should be possible to automate.

Segue to Tab Bar Controller with performSegueWithIdentifier

I'm learning iOS and I'm working on what amounts to a Proof of Concept app in XCode 4.2. I essentially want to allow a user to enter a user/pass combo and if the user is in an array of objects, pass them on to the "Content" view, but if not, pass them on to the "Register" view.
In either case, since the app itself will be a tabbed app (though the login and register views are not tabbed), I need to be able to segue from a typical ViewController to a TabViewController.
- (void)logIn:(id)sender{
[self performSegueWithIdentifier:#"Content" sender:sender];
}
Currently, I have the app segueing to the proper ViewController, which is a TabBarController embedded in a NavViewController...but once it gets there...there are no tabs!!
What am I doing wrong?
Now you aren't loading TabBarController that's why you don't have any tabs.
What I suggest you:
In Log In ViewController you can also add "register" button, and place a segue from it to Register View Controller.
Add IBAction from log in button, which will check for log in and pass, and if it's OK load Content ViewController or TabBar Controller with Content ViewController.
I strongly recommend you to study iOS5 storyboard tutorials to get to know how the view controllers interacts.

Can I use a single XIB to create full-resolution interfaces for both iPhone and iPad?

I want to load in an UISplitView an iPhone XIB, but it should be resized to full screen of the iPad... How can i do it? I dont want to convert the XIB itself!
I have read all the other solutions, but I do not want a second XIB, I just want to show it on both devices iPhone and iPad in its specific size.
So if I load it on the iPad by using the UISplitView, it should be in the full size, and if I load it on the iPhone, it should only have the iPhone size.
First off, there's no such thing as a UISplitView.
From the documentation:
The UISplitViewController class is a container view controller that manages the presentation of two side-by-side view controllers. You use this class to implement a master-detail interface, in which the left-side view controller presents a list of items and the right-side presents details of the selected item. Split view controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.
So UISplitViewController is just a container. You just pass a master view controller and a detail view controller to it. The master view will be displayed in a popover controller in portrait orientation.
I think either I misunderstood you or your approach is wrong. The reason why this class is not supported on the iPhone is because it wouldn't make any sense. You can't just "resize the splitview" or whatever, you have to redesign your interface separately for the phone. It's difficult to give you any concrete suggestion without knowing what you're doing. Figure out what are you trying to achieve, have a design, make separate nibs for each device and try to reuse code and views as much as possible.
Matt Gemmell wrote a SplitViewController that you can use as subview for the iPad (http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad/). You can check the source if you could use this for iPhone too. I found the source too heavy, I simply created an UITableView that loads other views when selecting a row (sort of a fake splitview).

How to design multiple views in iPhone

I am making code for iPhone. My first screen has only one button with text Menu. When user will click on this button next screen is coming with multiple navigation bar.Each Navigation bar has their own Text information which are being selected after clicking on any Navigation bar.
How i should to design it for iPhone ? Please give me concept. Should i take multiple views ? If i have multiple views how will i hide and show on button click event ?
Thanks in advance.
You will have to adapt your user interface to comply to how Apple wants an app to work, look, and feel - or make your own custom viewcontrollers. Even then, you might not get the exact behavior you want.
My hottest tip is to look at similar apps on appstore and see how they are navigated.
I don't get a picture in my mind from your description, but it seems you want what is called "drill down". This is best done with tableViews.
You can't have multiple navigation controllers on the same "screen"; it doesn't work like that on the iPhone. Instead, what you have is one single Navigation controller, that controls the pushing of views. You decide which sub-view to push depending on which selection the user makes, and the Navigation controller handles the rest of the interaction with the user to let him or her navigate between the views.
Example structure:
Window-based app
+-MainWindow.xib
| +-First view with button
| +-UINavigationController
+-tableview1.xib
+-tableview2.xib
+-any more views you need.
Make the app delegate a <UINavigationControllerDelegate> and declare navCt *UINavigationController, and connect it in Interface Builder. You can then write a pushVC method, which takes as argument a UIViewController *vc. It does a [navCt pushViewController:vc animated:YES];
Connect the button to an IBAction, which then calls the method in the app delegate, [PushVC myVC], where myVC refers to any viewcontroller in your app, in this case table view 1.
In this table, on didSelectRow... event you can use the same method to push the sub-view table view 2.
I think this is minimum code if you are unsure about iPhone app design. Either way, I hope it gives some ideas.
You should read about UINavigationController, UITabBarController, UIViewController.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
You almost always make one view pr. viewcontroller.

Top cell in UITableView hidden behind UINavigationBar

I have a UINavigationController controlling a stack of UIViewControllers. When I push a certain UITableViewController onto the stack, I find that the top row of its UITableView is hidden behind the UINavigationBar.
This problem only happens on the iPad, not the iPhone. I am using the same stack on both.
Also it only happens on one of my controller stacks. I push the same UITableViewController subclass on stacks controlled by two other UINavigationControllers, and there is no problem.
One difference in the problem case is that the UITableViewController is pushed from a UIViewController that is displaying the results table generated by a UISearchDisplayController. I don't see why this should matter (and, as I said, on the iPhone it works fine), but maybe it is significant given that a UISearchDisplayController hides the navigation bar when the UISearchBar becomes first responder.
The problem affects both the iPad device and the iPad simulator. I am using a typical UISplitViewController design, with these stacks in the left hand pane. The problem still occurs in the popover when in portrait.
I had the same problem after migrating an iphone app to a universal app. Here is what solved the problem for me. open your MainWindow.xib and dbl-click the window object. If it opens in iphone size you need to upgrade your nib. Select the document window and choose the menu item File > Create iPad Version. Save this nib with the name MainWindow-iPad.xib. Delete you original MainWindow.xib and add this one instead. After doing these steps problem disappeared and works fine for me on both iPad & iPhone.
Cheers, Harry