pushViewController from Prototype Cell - iphone

Quite simply, how do I push a new view controller from a prototype cell within a storyboard? I have a tableView reading data from a plist file, and its one default prototype cell on the storyboard. Then, I have another view controller in the storyboard I need to link to the tapping of a cell on the table view. How can this be accomplished?

Simplest thing would be to Ctrl-click on the prototype cell and drag the line onto the view controller that you want to transition to. It should prompt you for the type of transition—"push" transitions cause the new view controller's view to slide in from the right; "modal" transitions cause the new view to slide in from the bottom. Assuming you're using a navigation controller, the navigation bar should configure the back button automatically. You shouldn't need to write any code to achieve the behavior described in your question.

In your storyboard, link your prototype table view cell to your view
controller with a segue. Make sure to give the segue an identifier in
its Attributes Inspector.
In your TableViewController class,
implement - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
In the prepareForSegue: method, get the NSIndexPath of the row the user tapped with [self.tableView indexPathForSelectedRow]
Use the indexPath to get whatever data you need from your plist. Configure the view controller by using the destinationViewController property of the UIStoryboardSegue parameter passed into prepareForSegue:.

Related

Possible to have all cells segue to same view controller?

Instead of control-dragging every cell to the other view controller, is there a way to make them all segue to the view controller more easily? I would also need to add a Segue Identifier to the individual segues as well.
That is exactly why you have a tableview delegate method.
– tableView:didDeselectRowAtIndexPath:
whatever cell in the table this method will get invoked and there you can call for whichever transition like push,model etc programmatically in code.
This sounds like something you should do programmatically rather than in interface builder. You'll want to set the selection action for the cells to trigger the Segue.
You can create a manual segue from one view controller to another. Just select view controller from the bottom bar (where you see first responder and all) and ctrl drag to other view controller. Select the segue and give it a unique identifier (TransitionSegue in this example) from attributes inspector. From code call the segue whenever you want a transition.
[self performSegueWithIdentifier: #"TransitionSegue" sender: self];
Hope this helps.

interact the navigation controller bar button with embed container view

I've created a UIViewController, and insert a container view in it, which embed a UITableViewController. As the image described above.
When user click the Table View Cell, I'd like to add a UIBarButton on the Navigation bar.
But, how can I manage this? I can rise the DatePicker when click on Table View Cell, but when I call self.presentingViewController in table view controller implementation file, it returns (null), same as when I call self.parentViewController
You're probably trying to access the parent controller too early. If you log self.parentViewController in viewDidLoad, it will return null, but it should return the correct controller from viewDidAppear, and certainly from the didSelectRowAtIndexPath method. Using parentViewController in this context is correct, not presentingViewController.
I'd suggest to implement the UITableViewController Delegates and Datasource Methods in the ViewController itself.
That way you don't have to worry about accessing the ViewController containing the UITableView.

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 would I make a tableview lead to a page which had another tableview?

I want to make a tableview; when you press a cell it takes you to another tableview. If you press a cell on the second table, it takes you to another view. Then, you could go back if you want or whatever. How would I do this? I can make a tableview lead to a new view already, but the real question is how to make another tableview and lead to another view.
I'm not sure if I follow..
Anyhow, I recommend you create a UINavigationController and set the rootViewController to your tableView's controller view property, when a cell is tapped in your tableview you should implement:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
where you would create an instance of another view controller that holds your desired "different" tableview obviously and push it to the navigation controller.
I recommend you take a look at the view controllers programming guide as well as tableviews. It isn't that complex.
The key idea is to know that this behavior you want is basically how the navigation controller works by pushing and popping views.
If you implement it this way (which is what you should be doing) you get lots of functionality for free, such as the behavior when tapping on the "back" button.
Hope it helps.
Do you want to use both tables in the same view controller or do you want to use navigation controller to navigate to the next table view? If you want to use both the tables in the same view controller then differentiate them by tag value.

How do I have a Tableview go to another tableview

Right now I have an indexed tableview that goes to a detail view but i want it to go to another tableview then a detail view.
Any thoughts?
Use a UINavigationController with the first table view as its root view controller.
Implement the tableView:didSelectRowAtIndexPath: method of the table view's delegate to create the second table view (from a nib or programmatically, doesn't matter, as long as it's an instance of UITableViewController), then call the navigation controller's pushViewController:animated: method with the new controller.
Then, from the second controller, present your detail view as you are doing so already.
See also:
Using Navigation Controllers
Navigating a Data Hierarchy with Table Views
SimpleDrillDown sample project (may require registration)
The same way you would go to a detail view, but instead of transitioning to a view transition to a TableView.