Hello, I tried for 3 weeks to solve this problem and it will stun me. What I'm trying to do is create a 3-part segment from an array, display it in a view at a specific position, and then remove it from the view when the “OFF” flag is set. Everything works except deleting a segment. It will even commute with (pickOne) and display segments in the label. What I cannot find is either one of two things: setHidden: YES or removeAllSegments. Any help would be greatly appreciated. Here is my code.
- (void) showSegment {
int x = 192;
int y = 212;
int w = 125;
int h = 25;
SegUnit1 = @"A";
SegUnit2 = @"B";
SegUnit3 = @"C";
threeSegs = [NSArray arrayWithObjects: SegUnit1, SegUnit2, SegUnit3, nil];
segSize = [NSArray arrayWithArray:threeSegs];
UISegmentedControl *heightSC = [[UISegmentedControl alloc] initWithItems:segSize];
if ([segmentState_height isEqualToString:@"ON"]) {
NSLog(@"segmentState_height = %@",segmentState_height);
heightSC.frame = CGRectMake(x, y, w, h);
heightSC.segmentedControlStyle = UISegmentedControlStyleBar;
heightSC.selectedSegmentIndex = -1;
[heightSC addTarget:self
action:@selector(pickOne:)
forControlEvents:UIControlEventValueChanged];
[self.view addSubview:heightSC];
[heightSC release];
} else if ([segmentState_height isEqualToString:@"OFF"]) {
NSLog(@"segmentState_height = %@",segmentState_height);
[heightSC setHidden:YES];
[heightSC removeAllSegments];
}
}
Now I know that I need to “not” create and delete in the same function, and they gave him a hint to fix this issue, but I don’t know how to use the hint.
here is what was suggested.
, , . , .
, :
:
if ([self theControlProperty] == nil)
{
UISeg... *theControl = [[UISeg alloc] ....];
[self setTheControlProperty:theControl];
...
}
if (shouldHideTheControl)
{
[[self theControlProperty] setHidden:YES];
}
.