ios - UIButton not changing anything with @selector - new Issue -


need help. trying change image of imageview using programmed button. copied of sample codes out here. sitting on highlighted button works not doing else when clicked. thanks.

thanks replies. managed change photos created more problem. believe clear that new xcode.

new problems: 1. new image stays on top cannot access button. 2. have image changed when button highlighted. 3. new image, created warning: "hides instance variable" on relayimages properties. again.

.h file  -(void)changelabel:(uibutton *)sender;  -(void)addmybutton;  -(void)addmyimages;  -(void)addmylabel;  @property (nonatomic) uibutton *playbutton; @property (nonatomic) uiimageview *relayimages; @property (nonatomic, strong) uilabel *checkstatuslabel; @synthesize relayimages;   .m file - (void)viewdidload { [super viewdidload]; [self addmyimages]; [self addmybutton]; [self addmylabel];    // additional setup after loading view, typically nib. }  -(void)addmybutton { uibutton *playbutton = [[uibutton alloc] initwithframe:cgrectmake(100, 348, 20, 78)]; uiimage *offstate = [uiimage imagenamed:@"pbnooff.png"]; [playbutton setbackgroundimage:offstate forstate:uicontrolstatenormal]; uiimage *onstate = [uiimage imagenamed:@"pbnoon.png"]; [playbutton setbackgroundimage:onstate forstate:uicontrolstatehighlighted]; [playbutton addtarget:self action:@selector(changelabel:)    forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:playbutton];  }  -(void)changelabel:(uibutton *)sender {   uiimage *image1 = [uiimage imagenamed:@"1_2relayson.png"]; uiimageview *relayimages = [[uiimageview alloc] initwithimage:image1]; relayimages.frame = cgrectmake(0, 0, 320, 480); relayimages.backgroundcolor = [uicolor whitecolor]; [self.view addsubview:relayimages]; [self.view addsubview:_playbutton];    }   -(void)addmyimages { uiimage *image = [uiimage imagenamed:@"1_2relaysoff.png"]; uiimageview *relayimages = [[uiimageview alloc] initwithimage:image]; relayimages.frame = cgrectmake(0, 0, 320, 480); relayimages.backgroundcolor = [uicolor whitecolor]; [self.view addsubview:relayimages];  }  -(void)addmylabel { uilabel *checkstatuslabel = [[uilabel alloc] initwithframe:cgrectmake(10, 50, 200, 30)]; checkstatuslabel.backgroundcolor = [uicolor greencolor]; checkstatuslabel.textcolor = [uicolor whitecolor]; [self.view addsubview:checkstatuslabel];  } 

try created custom imageview

.m file

  -(void)addmybutton {     _playbutton = [[uibutton alloc] initwithframe:cgrectmake(100, 348, 60, 50)];     [_playbutton settitle:@"button" forstate:uicontrolstatenormal];     [_playbutton setbackgroundcolor:[uicolor graycolor]];     uiimage *offstate = [uiimage imagenamed:@"1.jpg"]; //    [playbutton setbackgroundimage:offstate forstate:uicontrolstatenormal]; //    uiimage *onstate = [uiimage imagenamed:@"pbnoon.png"];     [_playbutton setbackgroundimage:offstate forstate:uicontrolstatehighlighted];     [_playbutton addtarget:self action:@selector(changelabel:)    forcontrolevents:uicontroleventtouchupinside];     [self.view addsubview:_playbutton];  }  -(void)changelabel:(uibutton *)sender {       uiimage *image1 = [uiimage imagenamed:@"2.jpg"];     relayimages = [[uiimageview alloc] initwithimage:image1];     relayimages.frame = cgrectmake(20, 100, 100, 100);     relayimages.backgroundcolor = [uicolor whitecolor];     [self.view addsubview:relayimages];   }   -(void)addmyimages {     uiimage *image = [uiimage imagenamed:@"3.jpg"];     uiimageview *someimages = [[uiimageview alloc] initwithimage:image];     someimages.frame = cgrectmake(20, 200, 100, 100);     someimages.backgroundcolor = [uicolor whitecolor];     [self.view addsubview:someimages];  }      -(void)addmylabel {  _checkstatuslabel = [[uilabel alloc] initwithframe:cgrectmake(100, 250, 100, 30)];     _checkstatuslabel.backgroundcolor = [uicolor greencolor];     _checkstatuslabel.textcolor = [uicolor whitecolor];     [self.view addsubview:_checkstatuslabel];  } 

.h file

-(void)changelabel:(uibutton *)sender; -(void)addmybutton; -(void)addmyimages; -(void)addmylabel; @property (nonatomic) uibutton *playbutton; @property (nonatomic) uiimageview *relayimages; @property (nonatomic, strong) uilabel *checkstatuslabel; 

and viewdidload

 [self addmybutton];     [self addmyimages];     [self addmylabel]; 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -