0
votes

I have a tab bar controller with 3 view controllers and one navigation view controller in it. That navigation view controller has a table view controller and detail view.

In my first view controller (first tab) there are three buttons. I want the first button to load the detail view in the navigation controller. (as seen on image below)

Storyboard

How can i achieve this ?

I have tried calling the method that performs the segue in LocationsTableViewController, but that gives me the error "Receiver () has no segue with identifier 'addLocation'". Although a segue "addLocation" certainly exists.

Method connected to button in StartViewController:

- (IBAction)addLocationView:(id)sender {

    LocationsTableViewController *LTVC = [[LocationsTableViewController alloc] init];
    [LTVC addLocation];

}

LocationsTableViewController:

-(void)addLocation
{
    [self performSegueWithIdentifier: @"addLocation" sender: self];
}
1

1 Answers

0
votes

Your "addLocation" segue is from the Locations Table View Controller to the Add Location View Controller, so the segue exists on the LocationsTableViewController. That is correct. However, if your current view controller isn't LocationsTableViewController, it doesn't make sense to call that segue.

You have a few options:

  1. Storyboard Option #1: Make a new segue from StartViewController to AddLocationViewController, and perform that segue in addLocationView:.
  2. Storyboard Option #2: Make a new segue from the button to the AddLocationViewController, and remove your IBAction. The storyboard will automatically call that segue when the button is clicked.
  3. Programatic Option: Instantiate a new AddLocationViewController and push it onto the navigation stack: [self.navigationController pushViewController:[[AddLocationViewController alloc] init] animated:YES].