Reputation: 304
I am building an article reading app using storyboards.
I am also using AMSlideMenu Library for the main menu. I am facing an problem that is, i want to pass different url values when user click on different rows in AMSlideMenu.
here is my storyboad :
here is my code:
-(NSString *)segueIdentifierForIndexPathInLeftMenu:(NSIndexPath *)indexPath
{
NSString *idetifier = @"firstSegue";
// ysTableViewController *str;
switch (indexPath.row) {
case 0:
urlString = @"http://example.com/1";
break;
case 1:
urlString = @"http://example.com/2";
break;
case 2:
urlString = @"http://example.com/3";
break;
default:
urlString = @"http://example.com/4";
break;
}
return idetifier;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"firstSegue"])
{
ysTableViewController *controller = (ysTableViewController *)segue.destinationViewController;
NSLog(@"asgasfg-----%@",urlString);
controller.Mainlinks = urlString;
}
}
Upvotes: 0
Views: 216
Reputation: 11039
Make a subclass of AMSlideMenuLeftTableViewController
or AMSlideMenuRightTableViewController
(if you don't have already),
and implement following method
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UINavigationController *destNC = segue.destinationViewController;
UIViewController *destVC = nc.viewControllers.firstObject;
if ([segue.identifier isEqualToString:@"firstSegue"])
{
FirstViewController *vc = (FirstViewController *)destVC;
// pass your data to vc
// e.g.
vc.title = @"I'm from first row";
} else if ([segue.identifier isEqualToString:@"secondSegue"]) {
// same for others
//...
}
}
Upvotes: 0
Reputation: 304
I got over the problem by using NSUserDefaults temporarily but still it not a proper solution. Still looking for a proper method to pass parameters b/w classes.
Upvotes: 0
Reputation: 183
You can create a new UIViewController inside prepareForSegue method.
— YourTableViewController *newObj= [[YourTableViewController alloc]init]; - newObj.value=@"your value";
By This way u can pass your value.
Upvotes: 0