ios - 将数据从 didSelectRowAtIndexPath 传递到另一个 View Controller ios7

标签 ios ios7 uitableview didselectrowatindexpath

我正在尝试实现一个幻灯片菜单,当您选择一个选项时,它会向第二个 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/

相关文章:

ios - 更改 UISplitViewController iOS 8 中的详细导航项

ios7 - 如果无法访问 UIWebView 的运行时,为什么要在 iOS7 中使用 JavaScriptCore?

ios - UITableViews 上的点击与长按 - 为什么长按时点击不会选择行?

ios - TableView 加载数据后将表滚动到索引

ios - 从UICellView中的UIButton调用函数

ios - 比数据参数更多的 '%' 转换

ios - 非公共(public)选择器

ios - 为什么 __weak 对象会被添加到自动释放池中?

ios - UIImageView 未显示在 MKMapView 之上

ios - -[UITableView dequeueReusableCellWithIdentifier :forIndexPath:],/SourceCache/UIKit/UIKit-2903.23/UITableView.m:5261 断言失败