Display different screens dynamically using Uitableview

Asked

Viewed 208 times

2

Good guys, I’ll explain what I need to do. I need to create a table, where each row played, will have to show a screen (Actually, a standard skeleton) and fill this new screen with the data relating to it.

And be dynamic, because the table will be a list of items that will be added and removed.

For example: the iPhone Clock app, the Alarm Clock function. When you tap a line to edit an alarm, the screen that will open for editing is the same, but the data refers to that line you chose.

It will be a great help! Thank you.

2 answers

2


You can do this by two means.

The first you just set a property in the next UIViewController the type of object you want to display the information on. Once this is done, you urge UIViewController that you want to show the information.

For example:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
DetalhesEAlteracoesViewController *detalhesViewController = [storyboard instantiateViewControllerWithIdentifier:@"Detalhes"];
[detalhesViewController setObjeto: objetoASerDescrito];
[self.navigationController pushViewController:detalhesViewController animated:YES];
}

The second you can use another medium, which is via delegate navigation methods. Just use the function performSegueWithIdentifier: and also define a property in the UIViewController who wishes to submit the information.

Example:

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

In the delegate method of navigation you urge to UIViewController whether to define the object:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if ([[segue identifier] isEqualToString: @"Detalhes"]) {
    DetalhesEAlteracoesViewController *detalhesViewController = [segue destinationViewController];
    [detalhesViewController setObjeto: objetoASerDescrito];
    [self.navigationController pushViewController: detalhesViewController animated:YES];        
}
}
  • I will try and return with the result! Thank you!!

  • Good your code helped me! But I did the navigation using Static Cell. Then the cell behaves like a button through the storyboard and it is possible to use the navigation by push or model transiction. But thank you!!!

0

You can do:

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
  NSArray segues = @[ @"SegueLinha1", @"SegueLinha2", @"SegueLinha3" ];
  [self performSegueWithIdentifier:segues[indexPath.row] sender:self];
}
  • You can initialize the variable segue out of the method to avoid redundant processing

  • I think you mean indexPath.Row :)

  • Yes, that’s right. Thank you Otávio

Browser other questions tagged

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