0
votes

Fairly new to iOS development.

I have a ViewController embedded in a Navigation Controller.

In this ViewController I have two buttons (buttonOne and buttonTwo) which when pressed push to another view controller (ExerciseViewController).

The problem which i am facing is changing the title of the ExerciseViewController depending on which button is pressed.

So if buttonOne is pressed then title of ExerciseViewController is to be set to One.

if buttonTwo is pressed then title of ExerciseViewController is to be set to Two.

both view controllers have their own seperate classes.

..

ViewController.h - ViewController.m - ExerciseViewController.h - ExerciseViewController.m

Thanks for any help in advance.

1
Show the code where you push the view controller. Are you setting the title? Show that too... - Wain
It is pushed through storyboard.. title of the ExerciseViewController is left blank - user2512523

1 Answers

0
votes

You can implement prepareForSegue:sender: in your ViewController. It will be called and provide the triggering button. If you set a tag on the button or check which instance it is to decide what the title should be. Then you can set the title on the seque destinationViewController.

In your XIB, you can set the tag of the buttons to '1', and '2'. Or, in your viewDidLoad you can do:

self.buttonOne.tag = 1;
self.buttonTwo.tag = 2;

Then in prepareForSegue you can do:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showRecipeDetail"])
    {
        NSInteger tag = [(UIButton *)sender tag];

        certViewController *destViewController = segue.destinationViewController;      
        destViewController.title = (tag == 1 ? @"One" : @"Two");
    }
}