2014-12-19 2 views
0

모든 셀에 웹 뷰가 포함 된 tableview가 있습니다. 모든 셀에 활동 지표를 추가하고 싶습니다. 따라서 웹 뷰가 완료되지 않으면 해당 셀의 특정 활동 표시기가 중단되어야합니다. 물론 내 코드에서 webview delegate는 activityIndicator를 알지 못합니다. 어떻게해야합니까? 고마워.TableViewCell의 evey UIWebView ActivityIndicator

일부 코드 :

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

웹보기 대리인 : @pawan이 제안

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

    [activityIndicator stopAnimating]; 
} 
+0

당신이 뭔가를 시도했다 웹뷰 {

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

}? 여기에 코드를 게시하십시오 – Pawan

+0

몇 가지 코드를 추가했습니다. – tyler

+1

사용자 정의 셀을 만들고 웹 뷰 및 해당 델리게이트를 구현하도록 제안합니다. 여기에서 사용자 정의 셀을 사용할 수 있습니다.이 모든 것을 처리하는 더 좋은 방법입니다. – Pawan

답변

1

이보십시오.

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

{ 있는 UITableViewCell * 셀 =있는 tableView dequeueReusableCellWithIdentifier : 닐];

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; 

} - (무효) webViewDidFinishLoad : (UIWebView에서 *)

0

기본적으로, 가장 좋은 방법은이 CustomTableCell에 의해 달성하는 것입니다.

한편이 코드를 시도 :

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

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

[webview loadRequest:nsrequest]; 

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