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