我想将数据从一个 View Controller 传递到另一个不与 segue 相互连接的 View Controller 。 我知道最好的解决方案可能是使用 Delegate?但我该怎么做呢?
最佳答案
- (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的情况下在两个 View Controller 之间传递数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39315143/