gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:16:59 27 4
gpt4 key购买 nike

我有这个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/

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