gpt4 book ai didi

ios - 取消选择 Segment 的默认值

转载 作者:行者123 更新时间:2023-12-01 17:32:25 24 4
gpt4 key购买 nike

我正在尝试使用数组加载段控件。当我这样做时,它选择男性作为默认值。我不希望选择男性或女性,默认情况下都未选择。

- (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];
}

最佳答案

您可能应该使用:

[self.genderControl setSelectedSegmentIndex:UISegmentedControlNoSegment];

From Apple's doc:

The default value is UISegmentedControlNoSegment (no segment selected) until the user touches a segment. Set this property to -1 to turn off the current selection. UISegmentedControl ignores this property when the control is in momentary mode.

关于ios - 取消选择 Segment 的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16218012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com