如何从 UITableView didselectrowatindexpath 获取 webview? [英] How to Get webview from UITableView didselectrowatindexpath?
本文介绍了如何从 UITableView didselectrowatindexpath 获取 webview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这个视图中有一个 UITableview 我为每个单元格创建了 uiwebview.当我点击一个单元格时,我想要 UIWebView 的视图.如何实现这一目标??
I have a UITableview in this view i created uiwebview for each cell. When i tap on a cell i want the view of UIWebView. How to achieve this??
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"Cell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
cell.accessoryType = UITableViewCellAccessoryNone;
UIView *customView = [[UIView alloc]init];
customView.transform = CGAffineTransformMakeRotation(M_PI_2);
[customView setFrame:CGRectMake(0, 0, 1024, 768)];
[customView setBackgroundColor:[UIColor clearColor]];
UIWebView *menuWeb = [[UIWebView alloc]init];
[menuWeb setFrame:CGRectMake(0, 0, 768, 1024)];
[menuWeb setDelegate:self];
[menuWeb setUserInteractionEnabled:YES];
[menuWeb.scrollView setScrollEnabled:NO];
[menuWeb setScalesPageToFit:YES];
NSURL *url = [NSURL fileURLWithPath:[urlArr objectAtIndex:indexPath.row]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[menuWeb loadRequest:request];
[customView addSubview:menuWeb];
[cell.contentView addSubview:customView];
[cell setBackgroundColor:[UIColor clearColor]];
return cell;
}
推荐答案
in cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
....
UIView *customView = [[UIView alloc]init];
customView.tag = 100;
....
return cell;
}
并在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIView *customView = [cell.contentView viewWithTag:100];
for (id view in customView.subViews) {
if ([view isKindOfClass:[UIWebView class]]) {
UIWebView *menuWeb = (UIWebView *)view;
}
}
}
希望能帮到你
这篇关于如何从 UITableView didselectrowatindexpath 获取 webview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文