0

UIWebView我有一些我试图加载到单元格中的静态内容UITableView,以及交替单元格中的一些标签。这是我正在尝试的(不起作用): 在 vi​​ewDidLoad 中:

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;
}
4

2 回答 2

0

正确检查您的阵列,然后尝试,您的应用程序正在崩溃,并且错误与阵列相关。

于 2013-10-29T06:12:50.567 回答
0

尝试self.imageView.image = [UIImage imageNamed:@"Steve_Jobs.jpeg"];从子类 tableview 单元格中删除此行并重新检查标签和 webview 的框架。

于 2013-10-29T06:41:11.773 回答