Search code examples
objective-cxcodetagsuislider

UISlider with tag how to call?


I am trying to access or call an uislider based on the set tag.

for an example lets say i have a uislider named slider and i have given this slider a int tag of 1.

UISlider *slider = [[UISlider.......]];
slider.tag = 1;

how then would i access this slider object based on the tag value.

        [self updateSlider: [slider viewWithTag:1]];

will give me the following error

"Incompatible pointer types sending 'UIView *' to parameter of type 'UISlider *"

so my question is.

how would one call this objects based on the tag value? is it possible?


Solution

  • u can access the slider if u added it to view for example

    - (void)viewDidLoad
    {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
      UISlider *slider = [[UISlider alloc]...];
      slider.tag = 100;//setting the tag (set tag to some different higher numbers) 
      [self.view addSubview:slider];//added it to view
    }
    

    some where u are using the slider, but u want to access it with tag (as u said in your question) u can do it like below

    UISlider *slider = (UISlider *)[self.view viewWithTag:100]; //get the slider
    [self updateSlider: slider];//call to update slider