gpt4 book ai didi

ios - 如何从 UITableView didselectrowatindexpath 获取 webview?

转载 作者:行者123 更新时间:2023-11-29 03:10:11 26 4
gpt4 key购买 nike

我在这个 View 中有一个 UITableview 我为每个单元格创建了 uiwebview。当我点击一个单元格时,我想要 UIWebView 的 View 。如何实现这一点?

- (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;

}

最佳答案

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;
}
}
}

希望这会有所帮助

关于ios - 如何从 UITableView didselectrowatindexpath 获取 webview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22322728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com