I have a tableView. My tableView cells do have a detail accessory.
My question: How can I push another view controller when the detail button is presses.
When I normally press the cell, my ViewController1 opens. But when I tap on the little i on the right of the cell, I want to push a different view controller.
How can I do this?
it is just like DidSelectRow u need to modify DidSelectRow to accessoryButtonTappedForRowWithIndexPath
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// if u using .Xib
yourviewcontrollerName *vie=[[yourviewcontrollerName alloc]init];
[self.navigationController pushViewController: vie animated:YES];
//// if u using storyboard
[self performSegueWithIdentifier:#"yoursequeName"
sender:self];
}
you need more information use this link Pushing to a Detail View from a Table View Cell using Xcode Storyboard
Use this code it works
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// Push new View controller here
UIViewController *objVc=[[UIViewController alloc]init];
[self.navigationController pushViewController:objVc animated:YES]
}
Related
I used ShowDetailSegue to push a DetailVewController from another DetailViewController. there is no issues. But my need is to push to a DetailedViewController from a TableView in another DetailedViewController.
I used the below code for pushing:-
PushUpExerciseViewController *pushUpObj = [self.storyboard instantiateViewControllerWithIdentifier:#"PushUpID"];
[self presentViewController:pushUpObj animated:YES completion:nil];
After using this code in my TableView DidSelectRowAtIndexPath the MasterViewController is missing. i need both Master and Detailed ViewControllers. How to push from TableView in DetailViewController to another DetailViewController Programatically
Simply push to View Controller.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailVewController *objDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailVewController"];
//Pass the data here to DetailViewController
[self.navigationController pushViewController:objDetailVC animated:YES];
}
As you told you need to push DetailedViewController from another DetailedViewController instance on TableViewCell selection. In this case you need prevent the infinite loop of push.
Flow
Master (Push) -> Detail (Push on didSelectRowAtIndexPath ) -> Detail
I'm trying to connect two view controller into a one controller. As you can see below picture, when "plus" item is tapped the screen came and it works well. However, the other segue doesn't work properly. With my first tapping to any row, it doesn't take me to the view but after first tapping it starts taking me to the view as I wanted. I couldn't figure out why it doesn't take me to when I firstly tap any row. Here is the didSelectRowAtIndexPath code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
DovizDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
[self.navigationController pushViewController:detail animated:YES];
}
Below is my storyboard. The problem is about with the above view and it's segue.
Hope you can help me.
Thanks!
Change didDeselectRowAtIndexPath to didSelectRowAtIndexPath
IOS 6 , XCode 4.6.2 using storyboards
Heres my problem. I have a tableview with 7 cells using dynamic prototype. I would like to segue from the third cell to another tableview (which is going to allow the user to select a country and pass that country back.)
Is it possible to set this up so only that one cell triggers the segue ?
If its not, then I presume I would need to use the didSelectRowAtIndexPAth method - but if i haven't drawn a seque in the storyboard i cant call performSegueWithIdentifier because there is no identifier- and no segue
Any ideas what should do ?
Cheers
Simon
Don't draw your segue from the cell prototype in the table. Instead draw it from the Files Owner icon below your table view controller to the next table view controller. Give it an identifier and then call
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
in tableView:didSelectRowAtIndexPath.
If you don't have a segue between view controllers you can use push methods of UINavigationController.
If you already have a segue between the two view controllers you can do this:
-(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == yourCellIndex) {
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:objectThatYouSendOrNill];
}
}
If you are using static cells in your table view controller you can directly link segue from your cell to the destination view controller.
You can design the DetailViewController in storyboard itself. Give a StoryboardID for that view controller. and in didSelectRowAtIndexPath
-(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 3)
{
DetailViewController *viewController=[self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
[self.navigationController pushViewController:viewController animated:YES];
}
}
Dont forget to give StoryboardId for the DetailViewController as DetailViewController
I have a storyboard with tabbarcontroller. One of tab bar has a tableview and I want that when the user tap in a row from tableview open a detail view. The problem is when I open detail view tab bar and navigation bar hides... In the storyboard I create the detail view as a new view controller, then I create a new file and referred it to the class of detail view .
The code in didselectrowatindexpath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
detalleYouTube *dvController = [[detalleYouTube alloc] init];
[self.navigationController pushViewController:dvController animated:YES];
}
Thank you in advance!
This is kinda old but if someone needs to do this here's an easy approach:
You can use add a segue from the view in the tab bar to detalleYouTube, put an identifier to the segue and do this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"segueIdentifier" sender:tableView];
}
Another approach to this is not to use tableView:didSelectRowAtIndexPath but instead use prepareForSegue:sender
the way I did it was:
-(void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender
{
DetailViewController *viewController = [segue destinationViewController];
CustomObject *custObject = [arrayOfObjects objectAtIndex:[self.tableView indexPathForSelectedRow].row];
viewController.objectNeeded = custObject;
}
This example is based on the idea that your detail view controller is connected to your table view controller.
I presume you have the 'Detail' view as part of the storyboard (not in a separate XIB), if so you will need to place a separate NavigationController at the start of the 'Detail' TabBarItem seque.
This page has a good tutorial on what I think your trying to achieve:
http://maybelost.com/2011/10/tutorial-storyboard-in-xcode-4-2-with-navigation-controller-and-tabbar-controller-part1/
Also check these links to a more in-depth Storyboard tutorial:
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2
I have created a popover, containing a table
when user will select the row at that time I want to dismiss popover.
any Idea.
Have a look in the apple documentation... Have a look at the popoverclass...
When your table delegate method gets called, close the popover:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[popoverController dismissPopoverAnimated:YES];
// Handle the row click
}
Where popoverController is an instance variable set up when you created the popover.