ios-passing data between two view controllers with

2019-07-24 03:52发布

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条回答
叛逆
2楼-- · 2019-07-24 04:05
- (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:^{

  }];

  }
查看更多
登录 后发表回答