2012-05-12 95 views
0

我有真正的麻煩添加UIImageView到單個UITableView單元格。在我的故事板中,我有一個UITableViewController和四個原型動態單元。其中三個與正常的左側細節單元一樣好,並且它們工作正常。然而,其中一個我需要有一個UIImageView英寸將UIImageView添加到UITableViewCell?

所以我已經添加了所述視圖的單元格,給單元格的自定義類與屬性,所以我可以訪問圖像視圖。

我有以下單元格: 標題單元格。 Image Cell。 URL單元格。 評論Cell。

表視圖的內容根據用戶是否想添加URL,註釋或圖像而改變。所以用戶總是看到其中一個標題單元格。

這是我的代碼,無論什麼原因,我只是無法讓UIImageView顯示在該圖像單元上。希望你能幫忙看看有什麼不對,謝謝。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *CellIdentifier = @"Cell"; 

    //0 = Image 
    if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 0) 
    { 
     if (indexPath.row == 0) CellIdentifier = @"titleCell"; 
     if (indexPath.row == 1) CellIdentifier = @"imageCell"; 
     if (indexPath.row == 2) CellIdentifier = @"notesCell"; 
    } 
    //1 = URL 
    else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 1) 
    { 
     if (indexPath.row == 0) CellIdentifier = @"titleCell"; 
     if (indexPath.row == 1) CellIdentifier = @"urlCell"; 
     if (indexPath.row == 2) CellIdentifier = @"notesCell"; 
    } 
    //2 = Notes 
    else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 2) 
    { 
     if (indexPath.row == 0) CellIdentifier = @"titleCell"; 
     if (indexPath.row == 1) CellIdentifier = @"notesCell"; 
    } 

    ScrapbookImageDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[ScrapbookImageDetailCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier]; 
     cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    [cell setBackgroundColor:[UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f]]; 
    [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; 

    cell.textLabel.adjustsFontSizeToFitWidth = YES; 

    cell.textLabel.text = [firstSection objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13.0f]; 
    cell.detailTextLabel.numberOfLines = 0; 
    cell.accessoryView = nil; 

    switch (indexPath.section) 
    { 
     case 0: 
      switch (indexPath.row) 
     { 
      case 0: 
      {     
       cell.detailTextLabel.text = scrapbook.title; 
      } 
       break; 

      case 1: 
      { 
       //0 = Image 
       if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 0) 
       { 
        cell.detailTextLabel.text = nil; 
        cell.iv.image = [UIImage imageNamed:@"image.png"]; 
       } 
       //1 = URL 
       else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 1) 
       { 
        cell.detailTextLabel.text = scrapbook.url; 
       } 
       //2 = Notes 
       else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"NewScrapbookEntry"] == 2) 
       { 
        cell.detailTextLabel.text = scrapbook.notes; 
       } 
      } 
      break; 

      case 2: 
      { 
       cell.detailTextLabel.text = scrapbook.notes; 
      } 
      break; 

      default: 
       break; 
     } 
     break; 

     default: 
      break; 
    } 

    return cell; 
} 

回答

0

爲什麼你改變標識符的值?你只需要做自定義單元格,並在行高度,檢查它是否是你想要的行,並返回與圖像的高度其他默認大小,在行方法的單元格中的n,再次檢查所需的行,並添加圖像你想添加其他使圖像視圖無

+0

我明白你的意思,但我使用不同的單元格標識符的原因是因爲我有我的故事板中組成的自定義單元格,所以如果某個標識符用於某個indexPath,然後使用我的故事板中的單元格。基本上它可以讓我更容易地使我的自定義單元格可視化。 –

相關問題