ios - Make default value of Segment unselected -
i trying load segment control array. when selects male default. want neither male or female selected , both unselected default.
- (id)initwithanimal:(itanimal *)animal isedit:(bool)isedit { self = [super init]; if (self) { // custom initialization _animal = animal; _genders = [nsarray arraywithobjects:@"male", @"female", nil]; if (!_animal) { _animal = [[itdata sharedobject] managedobjectfromname:@"itanimal"]; _animal.gender = [_genders objectatindex:0]; } _isedit = isedit; // gender controll self.gendercontrol = [[uisegmentedcontrol alloc] initwithitems:_genders]; [self.gendercontrol addtarget:self action:@selector(genderchanged:) forcontrolevents:uicontroleventallevents]; } return self; } } else if (indexpath.row == 2) { bool isin = no; (id view in cell.contentview.subviews) { if ([view isequal:self.gendercontrol]) isin = yes; } if (!isin) [cell.contentview addsubview:self.gendercontrol]; [cell.detailtextlabel sethidden:_isedit]; [self.gendercontrol setselectedsegmentindex:[_genders indexofobject:content]]; [self.gendercontrol sethidden:!_isedit]; }
you should use :
[self.gendercontrol setselectedsegmentindex:uisegmentedcontrolnosegment];
the default value uisegmentedcontrolnosegment (no segment selected) until user touches segment. set property -1 turn off current selection. uisegmentedcontrol ignores property when control in momentary mode.