How to popViewController from button click of custom UITableViewCell - iphone

I have a button in a custom UITableViewCell. Its UITableView is controlled by a UIViewController. I would like to return to the RootView when that button is clicked.
I am trying to use
[self.superview.navigationController popViewControllerAnimated:YES];
in the target Action of the button, which is in the UITableViewCell.m file. However, it doesn't recognize "navigationController" because it is not in the stack.
How can I return to the RootView when that button is clicked?

Views have no explicit relation to controllers and views cannot be in the controller stack. Set the button target to be a UIViewController instance and in the action method call:
[self.navigationController popToRootViewControllerAnimated:YES|NO];

Related

Add button in UITabBarController in Storyboard

I have the following storyboard:
In the tab bar controller I have a add button with a segue to a view controller. I need to use the method "prepareForSegue:" because I need to transfer an object but in the Repositories Table View doesn't fire the method.
How can I detect the method "prepareForSegue:" in the Repositories Table View? Is it possible?
I suppose for "detect the method prepareForSegue" you mean "identify the right segue in the prepareForSegue method".
You do this by using [segue identifier] and the string comparison method isEqualToString: to compare it to what you set the Identifier to be in storyboard.
Also, make sure that the button, table view cell, button or other element is attached to the right segue. You can of course do that in storyboard as well. If you need to do it in code e.g. because the button is created programmatically, you will have to call the segue yourself. In the button handler you just use
[self performSegueWithIdentifier:"SegueIdentifier" sender:self];

How to create a navigation controller based view from a simple uiview?

I have a simple uiviewcontroller with 4 buttons. Every buttonclick event loads a different image on the view. However for the 4th button i want to launch a navigation controller based uiview with a uitableview. The table view can then have 3 levels which define the settings for the application.
On selecting a row in the uitableview on the 3rd level i need to return to my main view with the selected row index.
How can i add a navigation based view which will be launched on a button press event and the first view of the uinavigationcontroller should compose of a back button which will close this navigation view and return to main view.
TIA,
Praveen S
Edit:
My first(home) view does not need a navigation bar. The view launched from the home view should however consist of a navigation bar with back button.
if(nxtv12==nil){
nxtv12=[[v12 alloc] initWithNibName:#"v12" bundle:nil];
}
[self.navigationController pushViewController: nxtv12 animated:YES];
and for coming back to home.
[self.navigationController popToRootViewControllerAnimated:YES];
Create a UINavigationViewController object in the current UIViewController (or use self.navigationcontroller) and push the new UIView into the navigation controller. To come back to the same view, use popToRootViewControllerAnimated in the new UIView class.

Split view controller menu in w/o split view controller?

I am making an iPad app, and am wondering it is possible to get the pop down menu from a UINavigationBar without having to go through the trouble of a split view controller. Is this possible? Tell me if I'm not being specific enough.
Yes, you can do that without much trouble, but you just have to write the code. Just display a UIPopoverController from that UIBarButtonItem on your navBar.
The steps:
Create a UIViewController which manages a table view (or whatever else you want) as your menu view controller.
Add a UIBarButtonItem to your nav bar or toolbar.
Create an IBAction to called something like touchedMenuButton.
Connect that action to that UIBarButtonItem.
In that method, alloc/init that view controller.
alloc/init a UIPopoverController with that view controller.
present that popover from the UIBarButton item
Success!

tabBarController navigation problem/question

I have a simple tabBarController application where the user can navigate around 3 views.
In one of the views I have a UIButton that when touched moves the user to a fourth view. the problem is that the new view doesn't have the tab bar navigation visible.
what do I need to do to the fourth view to have it also use the tabBarController feature set.
thanks for any help
here's the code that transitions to the fourth view when a UIButton is touched:
-(IBAction) nextQuestion {
Question2 *q2 = [[Question2 alloc] initWithNibName:#"Question2" bundle:nil];
q2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:q2 animated:YES];
[q2 release];
}
A modal view controller always takes up the entire screen. Its purpose is to provide a modal interface that does not let the user interact with other parts of the UI until they dismiss the modal view.
To display another view inside a tab, you could make the root controller of that tab a navigation controller. A button tap would then push the Question 2 controller on the nav controller's stack.

Navigating between views using Toolbar

In my app, I require the main page to contain a toolbar at the top of the view. This view has a tableView. So my application cannot have a NavigationController.
Problem
When I want to navigate to the other view on click of the tableview cell then I am using the "pushViewController:animated:" method but it doesnt seem to work.
I checked the connections in IB. They are fine.
How can I navigate between pages without navigation controller??
I do not want to use the modal view for other views.
Please Suggest some Method.
You can use an instance of UINavigationController without having it displayed and using it for navigation.
Load your first view controller with your instance of UINavigationController in your appDelegate implementation.
Like:
FirstScreenController *fsc=[[FirstScreenController alloc]initWithNibName:#"FirstScreenController" bundle:nil];
UINavigationController *navigation=[[UINavigationController alloc]initWithRootViewController:fsc];
navigation.navigationBar.hidden=YES;
[window addSubview:navigation.view];
Here FirstScreenController can be your view controller having the toolbar and tableview.If you want to display another view on any click of the tableviewcell, call it this way.
[self.navigationController pushViewController:secondviewcontroller animated:NO];