I’m working on an iPhone project where I’ve inherited someone else’s code. I have a situation where viewController A has a UIWebView and it is set as the delegate of that UIWebView.
I also have a Class B which is set as the delegate of viewController A.
In an instance of B I want to send some javascript using stringByEvaluatingJavaScriptFromString to the UIWebView in viewController A.
What’s the best way of doing it?
You could make viewController A a delegate of Class B so that from Class B you can call a method on viewController A where the UIWebView could then execute the desired javascript.
Some things are missing above like where your instance of class B has it’s delegate property assigned to viewControllerA.
You would also need something like:
Manipulating UIElements should be left to the view controller that owns the UIElement, so for this reason I propose using a delegate. With a reference to viewController A you could directly manipulate the UIWebView, but I’d strongly advise against this. With code like this going on, who knows what other classes are also making changes on UIElements.