iphone - Setting Property on UIButton in Loop -
i'm spinning in circles on best way implement this, maybe can me out:
how can make when uibutton responds selector highlightimage, can set desired challengeid = index of appdelegate.availablearray?
in cellforrowatindexpath method, i'm creating uiscrollview buttons:
scrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0, 0, tv.frame.size.width, 78)];     [scrollview setcontentsize:cgsizemake(500, 78)];      [self createscrollbuttons];      [[cell contentview] addsubview:scrollview]; my createscrollbuttons loops , creates buttons in scrollview so, looping on number of elements in availablearray
- (void) createscrollbuttons {     superherogameappdelegate *appdelegate = (superherogameappdelegate *)[[uiapplication sharedapplication] delegate];      int x = 0;     int y = 0;     nslog(@"challenge array = %@",appdelegate.availablearray);     (int = 0; < [appdelegate.availablearray count]; i++) {         nslog(@" id= %d", [[[appdelegate.availablearray objectatindex:i]valueforkey:@"id"] intvalue]);         [self createbuttonatx:x andy:y withchallenge:[[appdelegate.availablearray objectatindex:i]valueforkey:@"id"]];         x += 90;     }  } createbuttonatx andy withchallenge called each element inavailablearray`, positioning them correctly along scrollview.
- (void)createbuttonatx:(int) x andy:(int) y withchallenge:(id)challengeid {     cgrect buttonrect = cgrectmake(x, y, 80, 78);      challengebutton *capebutton = [challengebutton buttonwithtype:uibuttontypecustom];      [capebutton setbackgroundcolor:[uicolor clearcolor]];     [capebutton setframe:buttonrect];      [capebutton addtarget:self action:@selector(highlightimage:) forcontrolevents:uicontroleventtouchupinside];      uiimage *capeimage = [uiimage imagenamed:@"capepower.png"];     [capebutton setbackgroundimage:capeimage forstate:uicontrolstatenormal];      [scrollview addsubview: capebutton]; } highlightimage called each buttons selector, determine button pressed.  (and ideally element availablearray button associated with)... i've subclasses uibutton , added int value able call [sender setchallengeid:]
- (void) highlightimage:(id)sender {      if([sender isselected] == no){         [sender setselected:yes];          [sender setchallengeid:selectedchallenge];         nslog(@"sender = %d",[sender challengeid]);              uiimage *selectedimage = [uiimage imagenamed:@"powerbarhand.png"];         [sender setbackgroundimage:selectedimage forstate:uicontrolstateselected];      }     else {         [sender setbackgroundimage:[uiimage imagenamed:@"handstandpower.png"] forstate:uicontrolstatenormal];            [sender setselected:no];         selectedchallenge = 0;     } } my problem cannot figure out how appdelegate's availablearray element highlightimage, uibutton's [capebutton addtarget:challengeid action:@selector(highlightimage:) forcontrolevents:uicontroleventtouchupinside] not allow me pass challengeid loop earlier in flow.
i able pass integer value setchallengeid, , handling expected.  need appdelegate.availablearray id value loop.
any direction great!:)
you availablearray highlightimage: same way got createscrollbuttons:
superherogameappdelegate *appdelegate = (superherogameappdelegate *)[[uiapplication sharedapplication] delegate]; and access appdelegate.availablearray.
i think that's not question meant ask, though. think want call setchallengeid: on each challengebutton create in createbuttonatx:andy:withchallenge:. in highlightimage: selectedchallenge = [sender challengeid] rather [sender setchallengeid:selectedchallenge].
Comments
Post a Comment