我正在尝试使用数组加载段控件。当我这样做时,它选择男性作为默认值。我不希望选择男性或女性,默认情况下都未选择。
- (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;
for (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];
}