How to open a new View after clicking on an item in a tableView

-1

I have a list of items inside a TableView I would like when clicking on an item in the list a new ViewController is opened containing the information referentere to the selected item I'm not able to make the view open using the method below:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    // Muro selecionado

    NSInteger linha= indexPath.row;

    Muro *c =[Muros objectAtIndex:linha];

     //navega para a tela detalhes

    DetalhesMuroViewController *detalhes = [[DetalhesMuroViewController alloc] init];

    detalhes.muro = c;

    [self.navigationController pushViewController:detalhes animated:YES];

What am I doing wrong?

In this link are all project files GaleRio .

I tried to use the second option and it returns me the following compilation error

No visible @interface for "DetailsMuroViewController" declares the "setItem" selector

The code looks more or less like this

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
DetalhesMuroViewController * detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"Detalhes"];

[detailViewController setItem:[Muros objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:detailViewController animated:YES];
}
    
asked by anonymous 01.12.2014 / 22:18

1 answer

0

You can do it in two ways.

The first one:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [self performSegueWithIdentifier:@"Segue" sender:self];
    }

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString: @"Segue"]) {
        DetalheItemViewController * itemInformationViewController = [segue destinationViewController];
        [itemInformationViewController setItem: item];
    }
}

The second:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];        
    DetalheItemViewController * detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"Detalhes"];

    [detailViewController setItem:[items objectAtIndex:indexPath.row]];
    [self.navigationController pushViewController:detailViewController animated:YES];
}
    
02.12.2014 / 11:36