objective-c - 在自定义 UITableViewCell 上实现 UIWebView

标签 objective-c ios uitableview uiwebview

我有这个UIWebView自定义内部UITableViewCell我创建的。

问题是,当我实现UIWebView时在"MyMain" ,它正在工作,但是当我滚动时,文本会在单元格上一次又一次地读取。

当我实现UIWebView时在自定义单元类本身中,它根本不显示它。

UITableViewCustomCell.h

@property (nonatomic, weak) IBOutlet UIWebView *wvMainText;
@property (nonatomic, strong) NSString *wvTitle;
@property (nonatomic, strong) NSString *wvPrice;

UITableViewCustomCell.m

@synthesize wvMainText = _wvMainText;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        // THIS IS WHERE I IMPLEMENT THE WEBVIEW?
    }
    return self;
}

MyMain

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"myListCell";

    UITableViewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"UITableViewCustomCell" owner:nil options:nil];

        for (UIView *view in views) {
            if([view isKindOfClass:[UITableViewCell class]])
            {
                cell = (UITableViewCustomCell *)view;
            }
        }
    }

    cell.wvTitle = [[self.arrList objectAtIndex:indexPath.row] valueForKey:@"title"];
    cell.wvPrice = [[self.arrList objectAtIndex:indexPath.row] valueForKey:@"price"];

    wv.scrollView.scrollEnabled = NO;

    NSString *htmlString = [NSString stringWithFormat:
                        @"<html><body>%@,%@</body></html>", self.wvTitle, self.wvPrice];

    [wv loadHTMLString:htmlString baseURL:nil];
    [wv setBackgroundColor:[UIColor clearColor]];
    [wv setOpaque:NO];

    return cell;
}

最佳答案

试试这个...它可能会解决您的问题。 在您的 cellForRowAtIndexPath 方法中,请进行如下更改......

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath         *)indexPath
{
static NSString *CellIdentifier = @"myListCell";

UITableViewCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

    NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"UITableViewCustomCell" owner:nil options:nil];

    for (UIView *view in views) {
        if([view isKindOfClass:[UITableViewCell class]])
        {
            cell = (UITableViewCustomCell *)view;
        }
    }
       cell.wvTitle = [[self.arrList objectAtIndex:indexPath.row] valueForKey:@"title"];
    cell.wvPrice = [[self.arrList objectAtIndex:indexPath.row] valueForKey:@"price"];

    wv.scrollView.scrollEnabled = NO;

    NSString *htmlString = [NSString stringWithFormat:
                    @"<html><body>%@,%@</body></html>", self.wvTitle, self.wvPrice];

    [wv loadHTMLString:htmlString baseURL:nil];
    [wv setBackgroundColor:[UIColor clearColor]];
    [wv setOpaque:NO];

}


    return cell;
}

关于objective-c - 在自定义 UITableViewCell 上实现 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13563207/

相关文章:

ios - 如何判断动画完成与否?

IOS订阅结束通知

ios - UITableViewCell - 无法让 UIButton subview 在 iOS 9 中重叠(并可点击)下一个单元格

ios - 在单独的文件中设置 UITableView 数据源和委托(delegate) - swift

ios - 在 : 以下使用 imagePickerController 委托(delegate)函数时获取模糊引用

ios - 界面构建器不允许添加表格 View 单元格

iphone - 停止更新位置后无法获得新位置 - IOS

ios - 属性(property)申报疯狂 iOS 7

objective-c - 我在我的 Cocoa 应用程序中添加了一个 WebView,它生成了一个错误

ios - 自定义一个 UITableViewCell 高亮样式