UITableViewController and pushing a DetailViewController on it - ios5

I have a UITableViewController and want to push a DetailViewController : UIViewController. Do I need to make the UITableViewController be part of a UINavigationController or can I just do a pushViewController from a UITableViewController?
I understand that UINavigationController (and UITabBarController) have a viewController's array that manages the viewing of view controllers. Does a UITableViewController have the same?
Sorry if question sounds convoluted.
thx

If you want a navigation stack where you can push and pop view controllers, you want the UINavigationController.
The easiest way to do it would be to place your UITableViewController into the UINavigationController (assuming that it is the first screen displayed) and then you can do a simple push from the controller. It would look something like this:
// First create viewController and then push it like this:
[self.navigationController pushViewController:viewController animated:YES];

Related

Problems with UINavigationController nested within moreViewController

I have UITabbarMoreController which contains a few UINavigationControllers. These UINavigationControllers then contain my custom view controllers.
So the hierarchy looks something like this:
UITabbarController
- UINavigationController
-> my custom UIViewController
- ...(other children of UITabbarController look the same)
From within my custom view controller I call [self parentViewController] which should return a UINavigationController. And this really happens, I really do get a UINavigationController, BUT only when the particular UINavigationController is NOT inside moreNavigationController.
Since I have many children controllers in the tabbar controller, the tabbar controller creates a moreNavigationController. If I open a viewcontroller that is under moreNavigationController and call [self parentViewController] it returns a mysterious object with class UIMoreNavigationController
I really need to get the UINavigationController that is parent of my view controller, not the UIMoreNavigationController. Also, I tried using [self navigationController] with the same result. How can I get reference to the real closest parent of my viewcontroller? Thanks for help in advance!
In short, you can't.
Apple always try to optimise their code. One of their optimisation here is to check whether the ViewController displayed in the list of its UIMoreNavigationController is of type UINavigationController. Because UIMoreNavigationController itself is a UINavigationController it does not want to create another UINavigationController. It's trying to avoid UINavigationController nesting.
When you look at the header file of UIMoreNavigationController you will notice it has a variable
UINavigationController* _originalNavigationController; which is accualy the original UINavigationController that you created and that you want to access. Unfortunetly you cant since UIMoreNavigationController is private.
Workaround (ugly)
Pass the reference of your NavigationController to its children when you push them on it's stack.

pushViewController:animated: inside ScrollView

I have a UINavigationController inside it I have a UIViewController handling a ScrollView just to use addSubview: and I am loading several UIViewController into the ScrollView.
I have a button referring to pushViewController:animated: but it does nothing.
I used self.parentViewController and self.presentedViewController but ran into the same issue.
This answer is based off of the title of this question. The question however, is not really a question at all, really.
UIViewControllers must be pushed form a UINavigationController. You cannot use a UIScrollView to push a view. You can use animations to move UIViews within the UIScrollView.
Maybe self.navigationController or self.parentViewController.navigationController is pushing nil .
Initiate a UINavigationController:
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:aViewController];
[self.navigationController pushViewController:nav animated:YES];
[nav release];
Try this. Hope this will help.
I got your problem. What should you do is create button or other view controllers dynamically and add them to UIView and then add this UIView to scrollView. You should add IBaction on runtime to every button and after that your navigation controller will work.
If your UIViewController is child of navigation controller then
[self.navigationController pushViewController:aViewController animated:YES]
will a push a viewcontroller over the present one.
Thats it!.

How can I set navigationController property of subview-viewController?

I have a UIViewController, and it has another UITableViewController as subview.
Table view is not visible, but in sometime it is visible by user's action. (for example, search table view.)
so, two new controller has no relation actually, (but UIViewController has UITableViewController as member variable), but only its view has parent - subview releation.
In this situation, user click the cell item in the table view, I have to push new view controller to navigation controller.
but only parent UIViewController is in navigationController, subview UITableViewController is not.
so code
[self pushViewController:viewController animated:YES];
fails in UITableViewController.
I solved this problem by passing navigationController instance of parent UIViewController to UITableViewController as property named parentNavigationController, and I called
[self.parentNavigationController pushViewController:viewController animated:YES];
instead.
It is solution that is not so bad, but I thinks it is some confused, I want to know is there more clearing solution.
How do you programming in this situation, friends?
I think parent-sub view relation of two view controller is confused, in the first. Is it better if I manage two views in one viewController? If then, view property of UITableViewController can be not table view? (and that view has table view as subview)
Thanks for your support, in advance.
Actually the concept is to push view controllers to the navigation stack of navigation controller. And UIViewControllers can only present modal view controllers, they can not push view controllers. So, sending pushViewController message to self(which is a UIViewController) is wrong. You can push a view controller using [self.navigationController pushViewController:anotherViewController];
In UITableViewController controller use self.navigationController instead of self.
[self.navigationController pushViewController:viewController animated:YES];

Create a UINavigationController to use inside a UITableViewController without Interface Builder

Maybe this is a too simple question but I'm kind of stuck here. I've implemented a class that inherits from UITableViewController. This class is the root controller of a split view I'm building by code, not with Interface Builder. The problem is that I'm trying to show a detail view from the accesory view in the table, and the navigationController attribute in my instance is nil. I don't have any idea of how to instantiate a new UINavigationController to be able to display a detailed view in my code.
This is how I'm trying to use the accesory button:
- (void)tableView:(UITableView *)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
PartDetailViewController *partDetailViewController =
[[PartDetailViewController alloc] initWithNibName:#"PartDetailView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:partDetailViewController animated:YES];
[partDetailViewController release];
}
Any hint would be really appreciated.
Thanks in advance,
Federico
If self.navigationController is nil means that you have not "pushed" your UITableViewController instance inside a navigation controller.
So I can imagine, from your description, that you have an iPad app with a UISplitViewController and your table has been instantiated inside the "root" view controller of the split view, so having a hierarchy like:
UISplitViewController ==>(root)==> UITableViewController
. If this is the case, what you have to do is to create a UINavigationController, push the table view controller inside the UINavigationController and then define the split view "root" controller to be the UINavigationController, according to this schema:
UISplitViewController ==>(root)==> UINavigationViewController ==> UITableViewController
Hope this can help you.
Create a UINavigationController, add the UITableViewCOntroller to the UINavigationController and add the UINavigationController to the split view's view.

Push UITabViewController from UIViewController is possible?

my app first viewController is UIViewController.
and when user click button firstView disappear and push UITabViewController
is it possible?
i can't find how to push UITabViewController from UIViewController.
UPDATE sorry, I misread TabVC for UITableViewController. Do you mean UITableViewController or UITabBarController? I'll leave my answer below anyways.
In this instance, it's usually best to have a UITabBarController be the root view object. Although it can be done, it's a messier implementation, in my opinion.
I would in fact make the UITabBarController the root and display the UIViewController modally from that UITabBarController on launch.
The user would be presented with the UIViewController and when they clicked the button, dismiss that modal view, revealing the UITabBarController.
Just use a UINavigationController.
Use the navigation controller to push the tableView as the second level in the hierarchy. As a bonus you'll get the back button for 'free' and you don't have to worry about delegates for getting back to the original UIViewController.
you may try this:
self.tabBarController.selectedViewController
= [self.tabBarController.viewControllers objectAtIndex:2];
it should work because selectedViewController property contains view of selected tab.
First of all you have view controller . And make Second view controller which contain tabbarcontroller . Now just push second view controller . And add tabbarcontroller's view as a subview to second view controller .
Hope you gets it ..