1

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?

  • 2
    Possible duplicate of [How to pass data between the view controllers without using segue](http://stackoverflow.com/questions/22932119/how-to-pass-data-between-the-view-controllers-without-using-segue) – Bista Sep 04 '16 at 08:53

1 Answers1

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

  }];

  }
Rokon
  • 355
  • 3
  • 11
  • thank you rokon but its not solve my problem.i send custom object but nothing changed.please look at my previous post http://stackoverflow.com/questions/39304240/send-data-to-detailview-from-favoritetableview – Mehdi Negahban Sep 04 '16 at 18:30