Checkbox image toggle in UITableViewCell

前端 未结 6 1437
执念已碎
执念已碎 2020-11-28 02:20

I need some guidance on creating a UITableViewCell that has an image on the left which can be toggled. The image should be tappable and act as a toggle (checkbo

6条回答
  •  执念已碎
    2020-11-28 02:31

    So the "..obviously need to massage some stuff.." comment means "...this code doesn't work...".

    So

    - (void) viewDidLoad
    

    should be

    - (id)initWithFrame:(CGRect)frame 
    {
     if ( self = [super initWithFrame: frame] ){
      normalImage = [UIImage imageNamed: @"toggleImageNormal.png"];
      selectedImage = [UIImage imageNamed: @"toggleImageSelected.png"];
      imageView = [[UIImageView alloc] initWithImage: normalImage];
    
     // set imageView frame
      [self addSubview: imageView];
    
      [self addTarget: self action: @selector(toggleImage) forControlEvents: UIControlEventTouchDown];
     }
    
     return self;
    }
    

    As - (void) viewDidLoad never gets called.

提交回复
热议问题