tags:

views:

68

answers:

1

I want to add a UISlider to my app programmatically without using the IB. I am adding a UISlider to my UIViewController using the code below. However I don't see the slider when the view comes up. What am I missing? I am using iPhone SDK 3.1.2. Appreciate any help.

@synthesize slider;
....

- (void)viewDidLoad {
...
...
slider = [[UISlider alloc] initWithFrame: CGRectMake(0, 480 - 80, 300, 20)];
slider.minimumValue = 0.0;
slider.maximumValue = 100.0;
slider.tag = 0;
slider.value = 50;
slider.continuous = YES;
slider.enabled = YES;
[slider addTarget:selfaction:@selector(handleSlider:)forControlEvents:UIControlEventValueChanged];
self.view addSubview:slider];

In the .h file

 ...
    UISlider    *slider;
    ...
    @property (nonatomic, retain) UISlider *slider;
    - (void) handleSlider:(id)sender;
A: 

Possibilities:

  1. If the slider isn't the last view added, its likely its being hidden by another view.
  2. The self.view is actually smaller than {0,400}.
  3. The sliders hidden attribute is set to true.
  4. You have more than one view controller active at a time.

You should check the debugger for the self.view's subviews and see if the slider is there. If so then it's almost certainly one of the reasons above.

TechZen