views:

198

answers:

1

Hi All,

Is there a way to detect when a UITextView has finished scrolling? As a note, I allow the user to enable or disable paging.

Thanks.

A: 

UITextView is a subclass of UIScrollView, which has a UIScrollViewDelegate class for controlling behaviour related to scrolling. One of its methods is scrollViewDidEndDecelerating. You can make your view controller implement this protocol, set your UITextView's delegate property to the view controller, and then implement the scrollViewDidEndDecelerating method. When the method is called, the UITextView will have finished scrolling. e.g.:

in .h:

@interface MyViewController : UIViewController <UIScrollViewDelegate>

in .m:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"Finished scrolling");
}
Shaggy Frog
Thanks. I think I got most of that except for setting the UITextView's delegate property to the view controller. Can you clarify on that? (I'm a newbie)
GL777
Sure. Once you have a delegate (in your case, your view controller), you need to tell the UITextView who the delegate is. You can do this visually in Interface Builder (click on the UITextView, bring up the Connections Inspector, drag from the `delegate` property to File's Owner), or inside code, inside your view controller's viewDidLoad method, with something like "myTextView.delegate = self;"
Shaggy Frog
Thanks! That worked! One thing: When I did it via the code(myTextView.delegate = self;) I get a warning saying "class MYCLASS does not implement the UITextDelegate protocol". Any ideas what that is? Thanks again!!!
GL777
btw, any chance you can help with this one, been working on it for days -- http://stackoverflow.com/questions/1338318/uitextview-paging-enabled-text-cut-off Thanks!
GL777
If MYCLASS is one of your UIViewControllers, then it should look similar to the live I have above, i.e., you need to add <UIScrollViewDelegate> to the end of the line.
Shaggy Frog
Not sure about that other question myself, sorry. :)
Shaggy Frog
I got it, instead of adding <UIScrollViewDelegate>, I added <UITextViewDelegate> and it worked with no warning. I guess it's because I was using it with UITextView. THANKS AGAIN FOR YOUR HELP!!! (and thanks for looking at the other one too, really appreciate it!)
GL777
No problem GL ;)
Shaggy Frog