2

カスタムセルを作成し、ラベルと画像を1つ追加しました。テーブルには4つの行があり、各行には異なる画像があり、各行は異なるView Controllerを開くため、特定の行をクリックすると必要になります画像を変更して試してみましたが、うまくいかないので、助けてください。

if(indexPath.row == 0)
{

     if(cell.selected == true)
     {
           UIImage *cellImage = [UIImage imageNamed:@"abc.png"];        
           cell.icon.image    = cellImage;
      }
      else
      {
          UIImage *cellImage = [UIImage imageNamed:@"abc.png"];        
           cell.icon.image    = cellImage;
      }
}

よろしくランジット

4

3 に答える 3

5

セルを作成するとき、またはtableView:willDisplayCell:forRowAtIndexPath:メソッドで次のことを試してください。

cell.imageView.image = [UIImage imageNamed:@"abc.png"];
cell.imageView.highlightedImage = [UIImage imageNamed:@"abc.png"];

もしそうなら、それはあなたのicon財産にも役立ちますUIImageView

于 2012-05-15T13:42:15.160 に答える
2

最初に uiImageview のカスタム セルにプロパティを作成し、合成します。

そして、UITabeViewのdidSelectRowAtIndexPathデリゲートメソッドでプロパティにアクセスし、画像を次のように変更します:-

yourCell.yourImageView.image=[UIImage imageNamed:@"yourImage"]

サンプルについては、コードを提供しています:-

#import <UIKit/UIKit.h>


@interface CustomizedCellProductDetails : UITableViewCell {

    UILabel *sNO;
    UILabel *abcWine;
    UILabel *redWine;
    UILabel *two;
    UILabel *hundred;
    UILabel *fourTwo;
    UILabel *twoOne;
    UIImageView *imgView;

    UILabel *itemNo;
    UILabel *itemName;
    UILabel *itemDesc;
    UILabel *department;
    UILabel *qtyAvailable;

    UIButton *check;

}

@property (nonatomic , retain) UILabel *sNO;
@property (nonatomic , retain) UILabel *abcWine;
@property (nonatomic , retain) UILabel *redWine;
@property (nonatomic , retain) UILabel *two;
@property (nonatomic , retain) UILabel *hundred;
@property (nonatomic , retain) UILabel *fourTwo;
@property (nonatomic , retain) UILabel *twoOne;
@property (nonatomic , retain) UIImageView *imgView;

@property (nonatomic , retain) UILabel *itemNo;
@property (nonatomic , retain) UILabel *itemName;
@property (nonatomic , retain) UILabel *itemDesc;
@property (nonatomic , retain) UILabel *department;
@property (nonatomic , retain) UILabel *qtyAvailable;
@property (nonatomic , retain) UIButton *check;

-(void) clicked;
@end

.m ファイルはそれを合成します:-

#import "CustomizedCellProductDetails.h"


@implementation CustomizedCellProductDetails
@synthesize sNO,abcWine,redWine,two,hundred,fourTwo,twoOne,imgView,itemNo,itemName,itemDesc,department,qtyAvailable,check;

テーブルビューデリゲートで:-

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here. Create and push another view controller.
    /*
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];
    */
CustomizedCellProductDetails * cell = (CustomizedCellProductDetails )[tableView cellForRowAtIndexPath:indexPath]; 
[cell.imgView setImage:[UIImage imageNamed:@"wine.png"]];

    }
于 2012-05-15T13:51:53.763 に答える