Search code examples
iphoneobjective-ccocoa-touchuislider

iPhone - Linking touch events to different classes/controllers


I have a UISlider inside a custom UITableViewCell named SliderCell.

I have a method in SliderCell which updates a UILabel to match the slider's value.

- (IBAction)sliderChanged:(id)sender;

I have the same method in a viewController that uses SliderCell in it's table. Base on the value of the slider, I want to reload an NSDictionary.

When I link the UISlider to SliderCell's method, it works. When I link the UISlider to viewController's method, it crashes the app without even displaying an NSLOG at the beginning of the method.

I linked the UISlider to the viewController by simply dragging my viewController class into my SlideCell nib. Does the app try to init another viewController instance?

How do I link it properly?


Solution

  • The correct way is to forget the interface builder and just do everything programmatically!!

    SEL action = @selector(someAction:);
    [myUISlider addTarget:self action:action forControlEvents:UIControlEventValueChanged];