I have a UIScrollView and contextView. I add UITextViews to it and set the delegate to self so that I can use the textViewShouldBeginEditing method. The textViewShouldBeginEditing is inside the same ViewController.m file, so the VC should be the delegate.
The textViewShouldBeginEditing method gets called and I want to check if the keyboard is blocking the textView and scroll it up if it's being blocked.
I want to call: [scrollView setContentOffset:CGPointMake(x, y) animated:YES]; However scrollView is not seen in textViewShouldBeginEditing.
I've seen where KVO can be used, but I want to use the delegate methods.
How can I gain access to the scrollView that the textView is on?
I didn't want to create a subclass of UITextView or use KVO.
The textViewShouldBeginEditing method gets called and I want to check if the keyboard is blocking the textView and scroll it up if it's being blocked.
I want to call: [scrollView setContentOffset:CGPointMake(x, y) animated:YES]; However scrollView is not seen in textViewShouldBeginEditing.
I've seen where KVO can be used, but I want to use the delegate methods.
How can I gain access to the scrollView that the textView is on?
Code:
- (void)viewDidLoad {
[superviewDidLoad];
UIScrollView *scrollView;
scrollView=[[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,320,480)];
scrollView.showsVerticalScrollIndicator=YES;
scrollView.scrollEnabled=YES;
scrollView.userInteractionEnabled=YES;
scrollView.contentSize = CGSizeMake(320, 1200);
scrollView.backgroundColor = [UIColorgrayColor];
[self.viewaddSubview:scrollView];
UIView *contentView;
contentView=[[UIViewalloc]initWithFrame:CGRectMake(0,0,320,480)];
contentView.userInteractionEnabled=YES;
[scrollView addSubview:contentView];
UITextView *myNewText = [UITextViewnew];
myNewText.delegate = (id)self;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
NSLog(@"BeginEditing");
// This is what I want to do, it doesn't show up in Xcode, but I'm in the same module and the VC is the delegate, because this method is being called.
// I just need to access the scrollView from in here to make it scroll.
//[scrollView setContentOffset:CGPointMake(x, y) animated:YES];
//[scrollView.contentOffset.x +320];
//scroll the view up if needed
returnYES;
}
I didn't want to create a subclass of UITextView or use KVO.