Reputation: 77
i am trying to implement a slide menu, where when you select an option, it sends a variable value to a second view controller, which has a query from parse, which would get updated based on the selected value from the slide menu.
how do i pass a variable from didSelectRowAtIndexPath to another view controller
@property (strong, nonatomic)NSString *passVariable;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = [NSString stringWithFormat:@"%@", [self.menu objectAtIndex:indexPath.row]];
UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
_passVariable = @"FieldName";
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;
self.slidingViewController.topViewController = newTopViewController;
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];
}];
}
NSString *vName = MenuViewViewController.passVariable;
tried the above, but the passVariable does not work in the secondViewController.m
Upvotes: 1
Views: 2719
Reputation: 11233
Two possibilities as I see:
1) Try using Singleton
approach: (if possible and necessary)
In menuViewController:
[Singleton sharedInstance].passVariable = @"yourValue here"
In secondViewController under viewDidLoad
:
someProperty = [Singleton sharedInstance].passVariable;
2) Try by making a property in secondViewController:
@property (nonatomic, copy) NSString * passVariable;
synthesize it:
@synthesize passVariable;
Now in menuViewController write like:
SecondViewController *newTopViewController = (SecondViewController*)[self.storyboard instantiateViewControllerWithIdentifier:identifier];
newTopViewController.passVariable = @"yourValue here";
Upvotes: 0
Reputation: 90117
You want to "push" objects to the next viewcontroller, not pull them from the previous viewController.
create a @property (copy, nonatomic) NSString *fieldName;
in your SecondViewController and use this:
SecondViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
newTopViewController.fieldName = @"FieldName";
Upvotes: 3