How to open a new view after clicking on an item on a tableView

Asked

Viewed 242 times

-1

I have a list of items inside a Tableview I would like when clicking on a list item a new Viewcontroller is opened containing the information referentere to the selected item I am unable 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 I’m doing wrong ?

At this link are all project files Galley.

I tried using the second option and it returns me the following build error

No Visible @interface for "Detalhesmuroviewcontroller" declares the selector "setItem"

The code went something 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];
}

1 answer

0


You can do it two ways.

The first:

- (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];
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.