UIWebView
我有一些我试图加载到单元格中的静态内容UITableView
,以及交替单元格中的一些标签。这是我正在尝试的(不起作用): 在 viewDidLoad 中:
commentArray = [[NSMutableArray alloc] initWithCapacity:5];
在视图中会出现:
[commentArray removeAllObjects];
[commentArray addObject:@"sketch here"];
[commentArray addObject:@"Heading1"];
[commentsJComments loadHTMLString:htmlString1 baseURL:baseURL];
[commentArray addObject:commentsJComments];
[commentArray addObject:@"Heading2"];
[commentsJComments loadHTMLString:htmlString2 baseURL:baseURL];
[commentArray addObject:commentsJComments];
在 cellForRowAtIndexPath 中:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath:
static NSString *reuseIdentifier = @"MyCell";
MyTableViewCellSubclass *cell = (MyTableViewCellSubclass *)[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (cell == nil)
{
cell = [[MyTableViewCellSubclass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
if (indexPath.row == 0)
// This image below ends up in every cell of my TableView:
cell.imageView.image = [UIImage imageNamed:@"Steve_Jobs.jpeg"];
else {
if (indexPath.row % 2 == 1)
cell.descriptionLabel.text = [commentArray objectAtIndex:indexPath.row];
else {
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[cell.textWV loadHTMLString:[commentArray objectAtIndex:indexPath.row] baseURL:baseURL];
}
}
我的子类 TableViewCell:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.textWV = [[UIWebView alloc] initWithFrame:CGRectMake(9, 0, 300, 400)];
self.textWV.scrollView.scrollEnabled = NO;
self.textWV.delegate = self;
self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, 300, 30)];
self.descriptionLabel.textColor = [UIColor blackColor];
self.descriptionLabel.font = [UIFont fontWithName:@"Arial" size:12.0f];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 281, 400)];
self.imageView.image = [UIImage imageNamed:@"Steve_Jobs.jpeg"];
[self addSubview:self.textWV];
[self addSubview:self.descriptionLabel];
[self addSubview:self.imageView];
}
return self;
}