David Raijmakers
David Raijmakers

Reputation: 1379

How to push DetailViewController from selectedRowAtIndexPath

When i click from my SecondViewController on a cell i want to go to my DetailViewController from the Storyboard.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSLog(@"Clicked at row: %@", [barCodeArray objectAtIndex:indexPath.row]);


}

How do i push to the DetailViewController and send [barCodeArray objectAtIndex:indexPath.row] with it?

EDIT :Not working code..

Code

/*DetailViewController *detailViewController1 = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController1 animated:YES]; 
[detailViewController1 release];
//[self.navigationController popViewControllerAnimated:YES];*/

enter image description here

Upvotes: 1

Views: 2465

Answers (1)

Wolverine
Wolverine

Reputation: 4329

Lets assume Listviewcontroller is your First view controller which contain a tableview. From that on didSelectRow you want to push Detailviewcontroller.

1.First check that your root view controller is Navigation Controller or not.

If you are using storyboard, then first your rootviewcontroller must be Navigation Controller

To check go to MainStoryboard file.

it should be something like this.

-> Navigation Controller -> Listviewcontroller -> Detailviewcontroller

2. Once it is confirmed that your rootviewcontroller is Navigation Controller. then to navigate from one Listviewcontroller to Detailviewcontroller you have to use "Segue"

Set a new segue from Listviewcontroller to Detailviewcontroller .

To set a new segue Ctrl-click on the prototype cell located in the Listviewcontroller scene and drag the resulting line to the Detailviewcontroller scene.

Upon releasing the line, select the Push option from the resulting menu.

The storyboard will update to display a segue connection between the table view and the Detailviewcontroller.

To open a Detailviewcontroller It will be necessary to reference this specific segue. In order to do so give an identifier. Click on the segue connection between Listviewcontroller and Detailviewcontroller, display the Attributes Inspector (View -> Utilities -> Show Attributes Inspector) and change the Identifier value to "Detailview".

In Listviewcontroller Add below method.

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([[segue identifier] isEqualToString:@"Detailview"])
        {
            DetailViewController *detailViewController =
            [segue destinationViewController];

            // and add any other code which you want to perform.

        }
}

For more information See this link

To add navigationcontroller in Tabbarcontroller......you can do like this added image. . Just

i think you need to see this link : In Storyboard with Navigation Controller and Tabbar Controller

Upvotes: 1

Related Questions