I have a custom UITableViewCell like this:
// Custom.h
@interface CustomQuestionCell : UITableViewCell {
IBOutlet UIWebView *mywebView;
}
-(void) AssignWebView:(NSString *) _text;
// Custom.m
-(void) AssignWebView:(NSString *) _text {
[mywebView loadHTMLString:_text baseURL:nil];
}
I can successfully use the UITableViewCell in UITableView in file called MainViewController. The delegate of UITableViewCell is MainViewController. In MainViewController I am calling below code to assign value to UIWebView.
// cellForRowAtIndexPath
//CustomQuestionCel.xib uses the class Custom defined above.
CustomQuestionCell *cell = (CustomQuestionCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"CustomQuestionCellView" owner:self options:nil];
cell = tblQuestionCell;
}
[cell AssignWebView:[ListOfQuestions object开发者_运维知识库AtIndex:indexPath.row]];
return cell;
My question is:
I would like to display an activity indicator in each cell while the UIWebView is loading the data.
How can I accomplish this?
1. In your CustomQuestionCell
header (.h file):
@interface CustomQuestionCell : UITableViewCell <UIWebViewDelegate> {
IBOutlet UIWebView *mywebView;
IBOutlet UIActivityIndicatorView *mySpinner;
}
2. In your CustomQuestionCell
implementation (.m file):
- (void) AssignWebView:(NSString *) _text {
[myWebView setDelegate:self];
[mywebView loadHTMLString:_text baseURL:nil];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[myWebView setHidden:YES];
[mySpinner startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[mySpinner stopAnimating];
[myWebView setHidden:NO];
}
3. In your CustomQuestionCellView
nib file insert a spinner (UIActivityIndicatorView
). Connect it as an mySpinner
outlet to your File's Owner
. Check Hides when stopped
checkbox and uncheck Animating
one.
精彩评论