Show different screens dynamically using UITableView

2

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

And let's dynamically, 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 is that line you chose.

It will be a great help! Thank you.

    
asked by anonymous 08.09.2014 / 03:39

2 answers

2

You can do this by two means.

The first thing you need to do is set a property in the next UIViewController of the type of object you want to display the information. When you do this, you instantiate the UIViewController 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 means, which is through the delegate navigation methods. Just use the performSegueWithIdentifier: function and also set a property on UIViewController you want to display the information.

Example:

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

In the delegate navigation method you instantiate UIViewController if you set 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];        
}
}
    
08.09.2014 / 14:42
0

You can do:

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
  NSArray segues = @[ @"SegueLinha1", @"SegueLinha2", @"SegueLinha3" ];
  [self performSegueWithIdentifier:segues[indexPath.row] sender:self];
}
    
22.05.2015 / 19:12