2016-09-04 100 views
1

我想將數據從一個視圖控制器傳遞給另一個視圖控制器,這些視圖控制器不通過segue.in firstviewcontroller互相連接,當按鈕觸摸(最喜歡)需要數據傳遞給屬於tabbarviewcontroller的secondviewcontroller(favoriteviewcontroller)時。 我知道最好的解決方案可能使用委託?但我該怎麼做?ios在兩個視圖控制器之間傳遞數據而沒有segue?

+2

的可能的複製[如何通過視圖控制器之間的數據,而無需使用賽格瑞](http://stackoverflow.com/questions/22932119/how-to-pass-data-between-the-view-controllers -without-using-segue) –

回答

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

    }]; 

    } 
+0

謝謝你rokon但它不解決我的問題。我發送自定義對象,但沒有任何changed.please看看我以前的帖子http://stackoverflow.com/questions/39304240/send-data-to-的DetailView從 - favoritetableview –

相關問題