I have a UIWebView
with a Bookmark button. The bookmarks are saved within a UITableView
. The name of the cell is the link of the bookmark. Now I want to click the cells and then the url of the bookmark should loud in my webview. But it does not work, when i click on the cells.
This is my code for this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [bookmarks objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
explorerView.urlField.text = [bookmarks objectAtIndex:indexPath.row];
[explorerView textFieldShouldReturn:explorerView.urlField];
[self.parentViewController dismissModalViewControllerAnimated:true];
}
Can you please give me a code example how to do this? This would be awesome.
You missing actual code, that will load URL in UIWebView
. You should add something like following code to your tableView:didSelectRowAtIndexPath:
NSString *URLString = [bookmarks objectAtIndex:indexPath.row];
NSURL *URL = [NSURL URLWithString: URLString];
NSURLRequest *URLRequest = [NSURLRequest requestWithURL:URLRequest];
[webView loadURLRequest:URLRequest];