I created a class (UIView) which has a UIScrollview inside. Through the delegate “scrollViewDidEndDecelerating” I can have 3 results (1,2,3).
How do I send this result to the main ViewController?
ViewController header
#import "Picker.h"
ViewController implementation
picker = [[Picker alloc]initWithFrame:CGRectMake(10, 10, 300, 300)];
[self.view addSubview:picker];
Picker implementation
(...)
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (scrollView.contentOffset.x <= 100) {
int result = 1;
} else if (scrollView.contentOffset.x > 100 && scrollView.contentOffset.x <= 200) {
int result = 2;
} else {
int result = 3;
}
}
(...)
I had to create a UIView class because it has other things in addition to Scrollview.
Thank you!
I suggest you create a
PickerDelegateprotocol with a method to return the required value to the main view controller.The Picker has a property:
Then you can set your view controller as the picker delegate using
picker.delegate = self;In the Picker UIView’s scrollview delegate method, you can pass the message to the view controller by using:
The view controller needs to implement the picker delegate method: