Reputation:
I'm trying to use storyboards segue instead of didSelectRowAtIndex.
This is what I have, but this method does not recognize indexPath.row. Is there an alternative I can use to do the same thing?
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SpecificExerciseTableViewController *upcomingViewController = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"Web"])
{
upcomingViewController.exerciseArray = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"exercises"];
upcomingViewController.muscleName = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
}
}
Upvotes: 2
Views: 2281
Reputation: 557
This trick works fine,heres an example of how I used it to pull parsed elements into a web view
.h file
@property (strong, nonatomic) NSString *url;
@property (strong, nonatomic) UIWebView *webView;
.m file
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
if ([segue.identifier isEqualToString:@"WebViewSegue"]) {
WebViewController *webViewController = segue.destinationViewController;
webViewController.url = (self.parseResults)[indexPath.row][@"link"];
webViewController.title = (self.parseResults)[indexPath.row][@"title"];
}
}
Upvotes: 0
Reputation: 659
Unless you have that indexPath as an ivar, no such variable exists in the scope.
If you would like to get the indexPath for the selected row in a UITableView use:
- (NSIndexPath *)indexPathForSelectedRow
The adjusted code for above:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
SpecificExerciseTableViewController *upcomingViewController = segue.destinationViewController;
if ([segue.identifier isEqualToString:@"Web"])
{
upcomingViewController.exerciseArray = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"exercises"];
upcomingViewController.muscleName = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
}
}
Upvotes: 5