Domanda

I am new to iOS programming and I am trying to make a ipad app that starts with a container view on the top that has a regular view controller with a 'banner' on top with a few buttons and a split view controller on bottom.

I want a button on this top banner to trigger the detail portion in the split view controller to return to the main page so it looks like how it originally started when the app was run.

Here is a picture of the app in the simulator showing the top banner with the split view controller beneath along with the button that I want to have a 'return home' function. This function would return the detail portion from a table view to the original collection view

runtime

Here is a picture of how the storyboard looks. You can see that the detail view has an embed segue to a collection view. When a button on the master view controller is pressed, the detail view segues from the collection view to the table view.

storyboard

How can I set up the button to my detail view to the original collection view?

I tried doing an NSNotificationCenter call that was made by pressing the button then calling dismissViewController. I tried it in both the home collection view controller as well as the table view controller. In the former, it did not even call the selector from the notification. in the latter, it did not dismiss the view controller.

I tried making an unwind segue action in the main collection view controller and then attaching the 'catalog' button to that segue but that did not seem to have any effect either.

Do you have any other suggestions I can follow or maybe clarify how I had done one of the above tactics wrong and how to correct it?

È stato utile?

Soluzione 2

I figured out a solution but feel free to comment/answer if you know of one that's more effective.

1) I went to the storyboard and created a segue from the table view controller to the main collection view controller

  • I made it a replace segue on the detail pane and gave it the name, "segueHome"

2) I created a method as follows in the table view controller

- (void)returnHome {
    NSLog(@"Ran returnHome");
    [self performSegueWithIdentifier:@"segueHome" sender:self];
}

3) I created the NSNotificationCenter stuff.

A. in the table view controller I added in the viewDidLoad method:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(returnHome) name:@"returnHome" object:nil];

B. in the table view controller I added the following method:

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"returnHome" object:nil];
}

c. in the banner view controller I added the following and connected it to the 'catalog' button

-(IBAction)returnHome:(id)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"returnHome" object:nil];
}

Together this should now return me home when I click catalog.

Altri suggerimenti

it all just depends on how you created the segue, if you have a modal segue you can dismiss the view controller with: [self dismissViewControllerAnimated:YES completion:nil];

if you have a navigation segue like what your picture has you can use a slightly different method call: [self.navigationController popViewControllerAnimated:YES]; or if you want to go to the root view controller use [self.navigationController popRootViewControllerAnimated:YES];

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top