Question

I have a simple Tab Bar app that within first Tab it has a UITextView and a UIButton, and the second Tab it's just a UILabel to display the text the user input on the first Tab.

The problem is that when I click the UIButton I don't know how to pass the data inserted by the user to the second Tab.

So anyone can help me with this code?

Thanks!!!

Was it helpful?

Solution

After tweaking with the suggestions I managed to solve the issue with this code:

- (IBAction)btnSaveToWatchlist:(id)sender {

[self performSegueWithIdentifier:@"MySegue" sender:sender];

}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {

    // Get destination view
     testVC *vc = [segue destinationViewController];

    // Get button tag number (or do whatever you need to do here, based on your object
    NSString *Title = self.title;

    // Pass the information to your destination view
    [vc setStrTitle:Title];
}
}

OTHER TIPS

UITabBarController has a property called viewControllers. It's an array that contains all the view controllers that the tab-bar controller can represent. By accessing the tab-bar controller from one view controller, you can access that array, and then you can then access the desired view controller whose text outlet you can change when the button from the first view controller is pressed.

I'm not entirely sure how to reference the UITabBarController from one of its child view controllers. It may be a preexisting property that is set during creation. If that's not the case. You can give all the view controllers of the tab-bar controller a reference to the parent manually during creation.

Let me know if you need further help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top