Today I’m working with an interesting problem. Right now, I have a first view that contains a webview, and then a separate view that contains a table with a list of URLs in a mutable array.
My question is,
How do I load a URL from the row selected in the table in the first view, into the webview that is in a separate viewController?
I assume I’m going to need this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
What I’ve done so far is set up a property for the webViewController, and what I’m working on now is passing it to the webView from the bookmarks view, but the help would be appreciated.
Thanks for your time!
- Jake
Well, you either need to implement an explicit intermediary class, or elect to adopt a design pattern that will enable communication. The two that come to mind in iOS would be a delegation pattern or a notification pattern.
In this case, my advice would be delegation. You’ll define a delegate protocol on your list controller, and you’ll conform to the protocol in your web view class. Somewhere up the chain the webview must be assigned as the table view’s delegate, and then, in the tableView’s didSelectRowAtIndexPath, you would implement the delegate call, passing the URL to the delegate, and the delegate then loads your URL in it’s own view.
How do I create delegates in Objective-C?