after searching, looking and experimenting I continue to fail at a specific problem. I am a programming novice, so by chance I simply did not use the right search term - so please bear with me in case I created a duplicate.

Here is the situation I'm struggling with.

ViewController 1 has two UIToolBars. The upper Toolbar Button displays a value, the lower Toolbar Button triggers an action in ViewController 2 which happens to be a TableViewController embedded via a container view. The reason for that is - I need the keep the ToolBars in place while scrolling the TableView.

I use a delegate protocol to send the value from VC2 to the upper Toolbar in VC1, works fine. But I fail to trigger the action in VC2 using the lower toolbar in VC1.

I kindly want to ask three question:

1.) What is the best practice to trigger the action / solve the problem ? 2.) How would the code look actually like when using a method named "theButtonWasTapped" on VC2 ? 3.) Is the method to embed the TableView via a container view the right way or is there a better way?

I tried to read through various documentations, but I don't even know where to start in this case.

Any help would be greatly appreciated since I'm sitting on this frustrated for days already and don't know where my mental block ends and my absent knowledge starts.

Thank you so much!

有帮助吗?

解决方案

If VC2 is embedded in a container view, then it will be a child view controller of VC1. Therefore you can access it from VC1 with self.childViewControllers[0]. So you should be able to do something like this in VC1:

-(IBAction)toolBarButtonTapped:(id) sender {
    SecondViewController *vc2 = self.childViewControllers[0];
    [vc2 methodInVC2];
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top