ios-passing data between two view controllers without segue?

早过忘川 提交于 2019-12-13 02:18:59

问题


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?


回答1:


- (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:^{

  }];

  }


来源:https://stackoverflow.com/questions/39315143/ios-passing-data-between-two-view-controllers-without-segue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!