ios - 在没有segue的情况下在两个 View Controller 之间传递数据?

标签 ios objective-c button delegates pass-data

我想将数据从一个 View Controller 传递到另一个不与 segue 相互连接的 View Controller 。 我知道最好的解决方案可能是使用 Delegate?但我该怎么做呢?

最佳答案

- (IBAction)showFavouriteViewController:(UIButton *)sender {
   //Create an instance of FavouriteViewController
   FavouriteViewController *fVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FavouriteViewController"];
   //Set public property of FavouriteViewController (these are the data you wanted to send)
   fVC.favouriteArray = @[@"Apple", @"Orange"];
   //Show the FavouriteViewController
   [self.navigationController showViewController:fVC sender:nil];
 }



- (IBAction)showFavouriteViewController:(UIButton *)sender {
  //Create an instance of FavouriteViewController
  FavouriteViewController *fVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FavouriteViewController"];
  //Set public property of FavouriteViewController (these are the data you wanted to send)
  fVC.favouriteArray = @[@"Apple", @"Orange"];
  //Show the FavouriteViewController
  [self.navigationController pushViewController:fVC animated:YES];

  }

 - (IBAction)showFavouriteViewController:(UIButton *)sender {
   //Create an instance of FavouriteViewController
   FavouriteViewController *fVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FavouriteViewController"];
  //Set public property of FavouriteViewController (these are the data you wanted to send)
  fVC.favouriteArray = @[@"Apple", @"Orange"];

  [self presentViewController:fVC animated:YES completion:^{

  }];

  // OR

  UINavigationController *nVC = [[UINavigationController alloc]   initWithRootViewController:fVC];
  //Presnet
  [self presentViewController:nVC animated:YES completion:^{

  }];

  }

关于ios - 在没有segue的情况下在两个 View Controller 之间传递数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39315143/

相关文章:

ios - 从 viewDidLoad 更改时,UIView 位置不遵守 NSLayoutConstraint

ios - 在 iOS 中模拟标签栏

ios - 删除项目然后添加到 UITableView 时出现异常

ios - 如何根据我的需要创建一个新的 iOS 框架?

javascript - 仅使用按钮类调用 Javascript

jquery - 使用包含按钮的回车键提交表单

ios - 递归上传目录 iOS AWS S3

ios - 使用视觉格式化语言在代码中自动布局 UIViewController

objective-c - 分配内存

java - 按钮监听器和 Action 监听器