UITableView:单击单元格并使用 UIWebView 打开单元格中的 link
UITableView: click on cells and open the link in cells with UIWebView
我有一个带有书签按钮的 UIWebView
。书签保存在 UITableView
中。单元格的名称是书签的 link。现在我想单击单元格,然后书签的 url 应该在我的网络视图中响亮。但是当我点击单元格时,它不起作用。
这是我的代码:
- (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];
}
你能给我一个代码示例吗?这太棒了。
您缺少实际代码,它将在 UIWebView
中加载 URL。您应该在 tableView:didSelectRowAtIndexPath:
中添加类似以下代码的内容
NSString *URLString = [bookmarks objectAtIndex:indexPath.row];
NSURL *URL = [NSURL URLWithString: URLString];
NSURLRequest *URLRequest = [NSURLRequest requestWithURL:URLRequest];
[webView loadURLRequest:URLRequest];
我有一个带有书签按钮的 UIWebView
。书签保存在 UITableView
中。单元格的名称是书签的 link。现在我想单击单元格,然后书签的 url 应该在我的网络视图中响亮。但是当我点击单元格时,它不起作用。
这是我的代码:
- (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];
}
你能给我一个代码示例吗?这太棒了。
您缺少实际代码,它将在 UIWebView
中加载 URL。您应该在 tableView:didSelectRowAtIndexPath:
NSString *URLString = [bookmarks objectAtIndex:indexPath.row];
NSURL *URL = [NSURL URLWithString: URLString];
NSURLRequest *URLRequest = [NSURLRequest requestWithURL:URLRequest];
[webView loadURLRequest:URLRequest];