gpt4 book ai didi

ios - UITableViewCell 中每个 WebView 的 ActivityIndi​​cator

转载 作者:行者123 更新时间:2023-11-29 02:25:42 24 4
gpt4 key购买 nike

我有一个表格 View ,其中包含每个单元格中的 WebView 。我想为每个单元格添加事件指示器。因此,只要 webview 完成加载,该单元格的特定事件指示器就应该停止动画。当然,我代码中的 webview 委托(delegate)不知道 activityIndi​​cator。我怎样才能做到这一点?谢谢。

部分代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;

if (cell == nil) {
NSLog(@"creating a new cell");

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]autorelease];

[tableView setRowHeight:screenHeight-15];



UIWebView *webview=[[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, screenWidth,screenHeight-95)]autorelease];

webview.delegate = self;

NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];

[webview loadRequest:nsrequest];

[self.view addSubview:webview];

[cell.contentView addSubview:webview];

UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]autorelease];
activityIndicator.center = CGPointMake(screenWidth/2, (screenHeight/2)-50);

[activityIndicator startAnimating];

[cell.contentView addSubview:activityIndicator];

}

return cell;
}

WebView 委托(delegate):

- (void)webViewDidFinishLoad:(UIWebView *)webView
{

[activityIndicator stopAnimating];
}

最佳答案

试试这个。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];

CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;

if (cell == nil) {
NSLog(@"creating a new cell");

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]autorelease];

[tableView setRowHeight:screenHeight-15];

UIWebView *webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, screenWidth,screenHeight-95)];

webview.delegate = self;
[webview setTag:indexPath.row];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]];

[webview loadRequest:nsrequest];
UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]autorelease];
activityIndicator.center = CGPointMake(webview.frame.size.width/2, (webview.frame.size.height/2)-50);
[activityIndicator setTag:500];
[activityIndicator startAnimating];

[webview addSubview:activityIndicator];

[cell.contentView addSubview:webview];


}

return cell;

}- (void)webViewDidFinishLoad:(UIWebView *)webView{

NSArray *arrSub=[[NSArray alloc]initWithArray:webView.subviews];
for (int i=0; i<[arrSub count]; i++) {
UIView *viewChild=[arrSub objectAtIndex:i];
if (viewChild.tag==500) {
if ([viewChild isKindOfClass:[UIActivityIndicatorView class]]) {
UIActivityIndicatorView *activityIndicator=(UIActivityIndicatorView*)viewChild;
[activityIndicator stopAnimating];
}
}
}

关于ios - UITableViewCell 中每个 WebView 的 ActivityIndi​​cator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27562906/

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