objective c - Can't see the button -


- (void)viewdidload{     int leftborder = 80;     int topborder = 160;     int width = 150;     int height = 50;     uiview *myview = [[uiview alloc] initwithframe:cgrectmake(leftborder, topborder, width, height)];     myview.layer.cornerradius = 5;     myview.backgroundcolor = [uicolor redcolor];     [self.view addsubview:myview];        uibutton *testbutton = [uibutton buttonwithtype:uibuttontyperoundedrect];     testbutton.frame = cgrectmake(0, 0, 50, 50);     [testbutton settitle:@"testbutton" forstate:uicontrolstatenormal];     [testbutton addtarget:self action:@selector(buttonclicked:) forcontrolevents:uicontroleventtouchupinside];     [self.myview addsubview:self.testbutton];      self.myview.hidden = yes;      [super viewdidload]; } 

hi, sorry stupid question! i'm newby in xcode. why didn't see button? , how can hide button after click? need button inside frame.

simple remove self.myview.hidden = yes;

to add click listener, 2 solution:

by code in viewdidload:

- (void)viewdidload {      [super viewdidload];      [mybutton addtarget:self action:@selector(mybuttonclick:) forcontrolevents:(uicontrolevents)uicontroleventtouchdown]; }  -  (void)mybuttonclick:(id)sender {     mybutton.hidden = yes; } 

or via interface builder (preferred), easiest way define handler/action in xcode using ibaction declaration in interface file (add declaration before @end statement). attach action button


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -