两个视图控制器之间的ios传递数据没有segue? [英] ios-passing data between two view controllers without segue?

查看:182
本文介绍了两个视图控制器之间的ios传递数据没有segue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据从一个视图控制器传递到另一个视图控制器,当一个按钮触摸(收藏夹)想要数据传递到作为tabbarviewcontroller的一部分的第二个视图控制器(favoriteviewcontroller)时,没有使用segue.in firstviewcontroller相互连接。
我知道最好的解决方案可能是使用Delegate?但是我该怎么做?

i want to pass data from one view controller to another view controller thats not connect to each other with segue.in firstviewcontroller when a button touch(favorite) want data pass to secondviewcontroller (favoriteviewcontroller) that is part of tabbarviewcontroller. i know that best solution maybe to use Delegate? but how can i do that?

推荐答案

- (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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆