iphone - child buttons of Reusable UITableViewCells not allowing me to update tag -
i attempting update tag of buttons within reusable uitableviewcell. first 5-8 cells there no issue setting tag these cells have not been "reused" yet understanding. 1 time ui have reuse cell, no longer allows me alter tag or set tag of button. missing?
uitableviewcell *cell =[tblplaces dequeuereusablecellwithidentifier:@"maintableviewcell"]; if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"maintableviewcell"]; } [[cell viewwithtag:107] settag:indexpath.section];
that isn't working because you're changing tag of button first cells created. when dequeue cell reused, it's button's tag has been changed before, no longer 107, it's whatever old index was.
i consider subclassing uitableviewcell , adding button property of subclass. way have direct access , wouldn't need utilize tags.
edit:
here's simple illustration of need do:
@interface mytableviewcell : uitableviewcell @property (nonatomic, retain) uibutton *mybutton; @end @implementation mytableviewcell -(id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { // create , add together button in here, or set equal 1 create in interface builder } homecoming self; } @end
iphone objective-c xcode
No comments:
Post a Comment