我想實現一個幻燈片菜單,其中當您選擇一個選項時,它將變量值發送到第二個視圖控制器,其中有一個查詢從解析,這將更新基於從滑動菜單中選擇的值。從didSelectRowAtIndexPath傳遞數據到另一個視圖控制器ios7
如何傳遞的變量從didSelectRowAtIndexPath方法到另一視圖控制器
menuViewController.h@property (strong, nonatomic)NSString *passVariable;
menuViewController.m
- (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];
}];
}
SecondViewController.m
NSString *vName = MenuViewViewController.passVariable;
嘗試了上面的內容,但passVariable在第二個ViewController.m中不起作用
要清楚的是,這個'didSelectRowAtIndexPath'方法在MenuViewController中嗎?另外,這'newTopViewController'是'SecondViewController'? – Shabib
是它在菜單vie控制器,並且newTopViewController不是第二個viewcontroller – mugunthan