objective-c – 在UITableViewCell内部动态查找UIWebView高度

我有一个这样的自定义UITableViewCell
// CustomQuestionCell.h
@interface CustomQuestionCell : UITableViewCell {

    IBOutlet UIWebView *mywebView;

}

-(void) AssignWebView:(Nsstring *) _text;

// CustomQuestionCell.m
-(void) AssignWebView:(Nsstring *) _text {

     [mywebView setDelegate:self];
    [mywebView loadHTMLString:_text baseURL:nil];

}

我可以在名为MainViewController的文件中的UITableView中成功使用UITableViewCell. UITableViewCell的delagate是CustomQuestionCell.在MainViewController中,我调用以下代码为UIwebview赋值.

// cellForRowAtIndexPath
//CustomQuestionCel.xib uses the class CustomQuestionCell defined above.

CustomQuestionCell *cell = (CustomQuestionCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if(cell == nil) {

    [[NSBundle mainBundle] loadNibNamed:@"CustomQuestionCellView" owner:self options:nil];
    cell = tblQuestionCell;
}

[cell AssignWebView:[listofQuestions objectAtIndex:indexPath.row]];



return cell;

我还在CustomQuestionCell.m中有以下代理代码

- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
    CGRect frame = aWebView.frame;
    frame.size.height = 1;
    aWebView.frame = frame;
    CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    aWebView.frame = frame;

    NSLog(@"webview frame size %f",aWebView.frame.size.height);
    [aWebView setopaque:NO];
    [aWebView setBackgroundColor:[UIColor colorWithRed:249.0/255 green:243.0/255 blue:236.0/255 alpha:1.0]];

    [activityLoad stopAnimating];
    [mywebView setHidden:NO];
}

我的问题是我无法在MainViewController中正确设置单元格的高度,它具有使用自定义单元格“CustomQuestionCell”的tableView.在功能

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

在MainViewController中如何设置单元格的高度为aWebView.frame.size.height ????

解决方法

最好的方式(我想)是创建一个代表.

CustomQuestionCell.h

@protocol CustomQuestionCellDelegate;

@interface CustomQuestionCell : UITableViewCell {
    IBOutlet UIWebView *mywebView;
    id <CustomQuestionCellDelegate> *delegate;
}

- (void)checkHeight;

@property (nonatomic,assign) id <CustomQuestionCellDelegate> *delegate;

@end

@protocol CustomQuestionCellDelegate <NSObject>

@optional
- (void)customQuestionCell:(CustomQuestionCell *)cell shouldAssignHeight:(CGFloat)newHeight;

@end

2. CustomQuestionCell.m(webViewDidFinishLoad

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...