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'开发者_StackOverflow社区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?
I think you need to change your declaration to:
-(IBAction) yourSliderValueChanged: (UISlider *) sender
then hook up the action to the slider.
Are you connecting the UISlider to the IBAction method in the viewController? Thats all you really should need to do
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];
精彩评论