ios - UISegmentedControl in static UITableViewCell -
i having strange problem uisegmentedcontrol not expected such simple interface element. have designed static cell tableview in storyboard (the table view has 8 cells, many of them interface elements steppers , labels work fine) contains uisegmentedcontrol. linked interface object following proper , method:
@property (strong, nonatomic) iboutlet uisegmentedcontrol *planthealthsegmentedcontrol; - (ibaction)planthealthvaluechanged:(id)sender; strangely, when initialize segmented control in viewdidload method, interface object not change default values set in storyboard editor. code used modify in implementation file table view:
planthealthsegmentedcontrol = [[uisegmentedcontrol alloc] initwithitems:[nsarray arraywithobjects:@"excellent", @"good", @"poor", @"dead", nil]]; planthealthsegmentedcontrol.tintcolor = gardengreencolor; planthealthsegmentedcontrol.selectedsegmentindex = 0; my planthealthvaluechanged method following (it logs -1 selected index)
- (ibaction)planthealthvaluechanged:(id)sender { nslog(@"segmented control index = %i", planthealthsegmentedcontrol.selectedsegmentindex); } any strange issue appreciated!
the problem reinitializing control. wipes out storyboard reference , makes brand new 1 isn't hooked anything.
you need rid of line:
planthealthsegmentedcontrol = [[uisegmentedcontrol alloc] initwithitems:[nsarray arraywithobjects:@"excellent", @"good", @"poor", @"dead", nil]]; i recommend setting segment info in interface builder directly since create control there.
or if want in code there few ways. can use insertsegmentwithtitle:atindex:animated: add them individually. if however, segments coming nib, want call removeallsegments first.
Comments
Post a Comment