我想将数据从一个视图控制器传递到另一个视图控制器,当按钮触摸(收藏夹)希望数据传递给tabbarviewcontroller的一部分secondviewcontroller(favoriteviewcontroller)时,使用segue.in firstviewcontroller不能彼此连接。 我知道最好的解决方案可能是使用Delegate?但我怎么能这样做?
答案 0 :(得分: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:^{
}];
}