问题
I am currently trying to convert my apps to Storyboards. My data is currently stored in a plist file and I drill down through my tableviews very easily using the following code in my current didSelectRowAtIndexPath:
method:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
NSArray *children = [dictionary objectForKey:@"Children"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([children count] == 0)
{
NSString *tempString1 = [dictionary valueForKeyPath:@"Movie"];
NSString *tempString2 = [dictionary valueForKeyPath:@"Text"];
NSString *tempString3 = [dictionary valueForKeyPath:@"Diagram"];
DetailsVC *dvc = [[DetailsVC alloc] initWithNibName:@"DetailsVC" bundle:nil];
dvc.movie = tempString1;
dvc.pdfdesc = tempString2;
dvc.pdfDiagram = tempString3;
dvc.navigationItem.title = [dictionary valueForKeyPath:@"Title"];
[self.navigationController pushViewController:dvc animated:YES];
}
else
{
LevelsVC *lvc = [[LevelsVC alloc] initWithNibName:@"LevelsVC" bundle:[NSBundle mainBundle]];
lvc.currentLevel += 1;
lvc.navigationItem.title = [dictionary valueForKeyPath:@"Title"];
[self.navigationController pushViewController:lvc animated:YES];
lvc.tableDataSource = children;
}
My question is: How on earth do I convert this method for use with Segues and Storyboards? I can easily create a segue for detailViews, and there are a million tutorials for that on the net, but i simply cannot figure out how to drill down through the data in my tableview.
Any help or sample code would be greatly appreciated!
回答1:
You can use -performSegueWithIdentifier:sender:
to transition from one view controller to another programmatically. Just move the code that configures dvc
to your -prepareForSegue:sender:
implementation.
Another option is to connect your segue in the storyboard from a cell in the table to the next view controller. That will cause the segue to be triggered as soon as the row is selected, which prevents you from having to start the segue programmatically at all. In that case, you just implement -prepareForSegue:sender:
to set any necessary data in the segue's destination view controller. The sender
parameter will be the table cell that was tapped, and you can use that to find the selected row.
来源:https://stackoverflow.com/questions/17711013/programming-tableviews-segue-drill-down