我正在尝试实现一个幻灯片菜单,当您选择一个选项时,它会向第二个 View Controller 发送一个变量值,该 Controller 具有来自解析的查询,该查询将根据幻灯片菜单中的选定值进行更新。
我如何将变量从 didSelectRowAtIndexPath 传递到另一个 View Controller
菜单 View Controller .h
@property (strong, nonatomic)NSString *passVariable;
菜单 View Controller .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];
}];
}
第二 View Controller .m
NSString *vName = MenuViewViewController.passVariable;
尝试了上述方法,但 passVariable 在 secondViewController.m 中不起作用
最佳答案
您想将对象“推送”到下一个 View Controller ,而不是从前一个 View Controller 中拉出它们。
创建 @property (copy, nonatomic) NSString *fieldName;
在您的 SecondViewController 中并使用它:
SecondViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
newTopViewController.fieldName = @"FieldName";
关于ios - 将数据从 didSelectRowAtIndexPath 传递到另一个 View Controller ios7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21597118/