Here's the code i am using to draw a custom slider but its disappearing when i started dragging it.
-(void)addSliderX:frame andminimumValue:(int)min andmaximumValue:(int)max andSliderValue:(int)value{
CGRect frame1 = CGRectFromString(frame);
statSlider = [[UISlider alloc]initWithFrame:frame1];
//[statSlider setMinimumTrackImage:[[UIImage imageNamed:@"greenSlider.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:10.0] forState:UIControlStateNormal];
[statSlider setMinimumTrackImage:[[UIImage imageNamed:@"sliderBar_green_stretch.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[statSlider setMaximumTrackImage:[[UIImage imageNamed:@"sliderBar_brown_stretch.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[statSlider setThumbImage:[UIImage imageNamed:@"sliderBar_greenThumb.png"] forState:UIControlStateNormal];
[statSlider setMinimumValue:min];
[statSlider setMaximumValue:max];
statSlider.continuous = NO;
positionX = value;
UIFont * font = YEAR_LABEL_FONT;
[statSlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[statSlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventTouchUpInside];
UIView * bubble2 = [[UIView alloc]init];
UIImageView * back2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sliderBar_handle_number.png"]];
UILabel * val = [[UILabel alloc]init];
UIButton * newB = [ApplicationHelpers buttonWithTitle:@"" andBgColor:[UIColor clearColor] andTitleColor:DESC_Color_White andTitleFont:font];
UIImage *buttonImage2 = [UIImage imageNamed:@"sliderBar_handle_number.png"];
UIImage *strechableButtonImage2 = [buttonImage2 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[newB setBackgroundImage:strechableButtonImage2 forState:UIControlStateNormal];
bubble2.tag = viewTag +1;
back2.tag = viewTag + 2;
val.tag = viewTag + 3;
newB.tag = viewTag + 4;
/*bubble2.alpha = 0;
back2.alpha = 0;
val.alpha = 0;*/
bubble2.hidden = YES;
back2.hidden = YES;
val.hidden = YES;
[self.view addSubview:statSlider];
//[self.view addSubview:bubble2];
[self.view addSubview:newB];
[bubble2 addSubview:back2];
[bubble2 addSubview:val];
}
// create the bubble over slider
-(void)valueChanged:(id)sender{
UISlider *localSlider = (UISlider *)sender;
greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]];
dsp =[greenSliderValue floatValue];
UIView * bubble2 = (UIView*)[self.view viewWithTag:151186];
UIButton * newB = (UIButton*)[self.view viewWithTag:151189];
UIImageView * back2 = (UIImageView*)[bubble2 viewWithTag:151187];
UILabel * val = (UILabel*)[bubble2 viewWithTag:151188];
NSString *valString = [NSString stringWithFormat:@"%3.0f", [localSlider value]];
[val setText:valString];
[newB setTitle:valString forState:UIControlStateNormal];
[newB setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
UIFont * font = YEAR_LABEL_FONT;
val.font = font;
val.textColor = DESC_Color_White;
bubble2.hidden = NO;
back2.hidden = NO;
val.hidden = NO;
newB.hidden = NO;
CGFloat sliderMax = localSlider.maximumValue;
CGFloat sliderMin = localSlider.minimumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = dsp;
CGFloat xCoord = 65.0-42.0;
CGFloat yCoord = (CGFloat)positionX;
CGFloat halfMax = (sliderMax+sliderMin)/2.0;
if (sliderValue > halfMax)
{
xCoord = xCoord-(sliderValue-halfMax);
}
else
{
xCoord = xCoord + (halfMax-sliderValue);
}
xCoord= xCoord + (600/sliderMaxMinDiff)*(sliderValue-sliderMin);
newB.frame = CGRectMake(xCoord,yCoord,84,47);
}
// Gets activated when slider is moved
-(void)sliderChanged:(id)sender{
i = i+1;
UISlider *localSlider = (UISlider *)sender;
greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]];
dsp =[greenSliderValue floatValue];
currentDict = [[totalDict objectForKey:[[totalDict objectForKey:@"Screens"]objectAtIndex:i]]retain];
NSString * identifier = [currentDict objectForKey:@"identifier"];
if ([identifier isEqualToString:@"end"]) {
NSDictionary * completed = [currentDict objectForKey:@"Completed"];
NSString * frameD = [completed objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameD);
NSString * frameString2 = NSStringFromCGRect(frame3);
NSString * label = [completed objectForKey:@"Dest"];
[self doneButtons:label andFrame:frameString2];
[sliderBox removeFromSuperview];
[yes removeFromSuperview];
[no removeFromSuperview];
[next removeFromSuperview];
[statSlider removeFromSuperview];
[self estimateButtons:@" Estimate." andFrameX:509 andFrameY:520 andFrameW:234 andFrameH:54];
}
else {
NSDictionary * quest = [currentDict objectForKey:@"Question"];
NSString * text = [quest objectForKey:@"Text"];
NSString * frameQ = [quest objectForKey:@"Frame"];
CGRect frame1 = CGRectFromString(frameQ);
NSString * frameString = NSStringFromCGRect(frame1);
if ([identifier isEqualToString:@"Yes"])
{
NSDictionary * selectable1 = [currentDict objectForKey:@"Selectable1"];
NSString * frameYes = [selectable1 objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameYes);
NSString * frameString3 = NSStringFromCGRect(frame3);
NSDictionary * selectable2 = [currentDict objectForKey:@"Selectable2"];
NSString * frameNo = [selectable2 objectForKey:@"Frame"];
CGRect frame4 = CGRectFromString(frameNo);
NSString * frameString4 = NSStringFromCGRect(frame4);
select.hidden = YES;
[yes removeFromSuperview];
[no removeFromSuperview];
[self yesButton:@" Yes." andFrame:frameString3];
[self noButton:@" No." andFrame:frameString4];
}
else
{
NSDictionary * selectable = [currentDict objectForKey:@"Selectable"];
NSString * frameBu = [selectable objectForKey:@"Frame"];
CGRect frame2 = CGRectFromString(frameBu);
NSString * frameString1 = NSStringFromCGRect(frame2);
select.hidden = YES;
[self selectButtons:@" Select." andFrame:frameString1 andValue:goal];
}
NSDictionary * completed = [currentDict objectForKey:@"Completed"];
NSString * frameD = [completed objectForKey:@"Frame"];
CGRect frame3 = CGRectFromString(frameD);
NSString * frameString2 = NSStringFromCGRect(frame3);
NSString * label = [completed objectForKey:@"Dest"];
UIView * bubble2 = (UIView*)[self.view viewWithTag:1];
UIButton * newB = (UIButton*)[self.view viewWithTag:151189];
[newB removeFromSuperview];
[bubble2 removeFromSuperview];
[greenSliderValue release];
[statSlider removeFromSuperview];
[trade removeFromSuperview];
[sliderBox removeFromSuperview];
[slidValue removeFromSuperview];
[next removeFromSuperview];
[self question:text andFrame:frameString];
[self doneButtons:label andFrame:frameString2];
}
}
Have you put break points on "[sliderBox removeFromSuperview]" in -(void)sliderChanged:(id)sender and checked if they are getting hit? - that seems like it could cause the removal of the slider from your container view.