yes there seems to be some confusion here.

1) the delegate for a UITextView is a UITextViewDelegate, the UIScrollViewDelegate is irrelevant.

2) It may well be that UITextView itself is a delegate of a scroll view behind the scenes and your override of its delegate method scrollViewDidScroll: is getting called giving you access to the UIScrollView delegate events, but that's not documented (as far as I can tell) so you shouldn't rely on it. I can't see anywhere in the documentation that a UITextView exposes any underlying scroll events. Also, you're not calling the superclass implementation, which would probably break the UITextView anyway.

3) Your implementation header for EVTextViewController says it implements the delegate protocols, but you've actually implemented them on the EVLessonTextView. That's why you get a warning when you assign the EVLessonTextView to the delegate, it doesn't implement the correct protocol or rather it does, but the compiler doesn't know that. When you set it to 'self' (ie an EVTextViewController) you don't get a warning because you've declared that the EVTextViewController does implement the delegate protocols, but you don't get any calls because it doesn't actually implement the methods, your other class does. You either need this

@interface EVLessonTextView <UITextViewDelegate>
@end

@implementation EVLessonTextView
.. UITextViewDelegate Methods here ...
@end

and then assign textView.delegate = textView

OR

@interface EVTextViewController <UITextViewDelegate>
@end

@implementation EVTextViewController
... UITextViewDelegate Methods here ..
@end

with textView.delegate = self


see how you've mixed up the two, declaration in one class, implementation in the other. The compiler warning was helping you.

4) repeating 2). I don't think the information you want is exposed by UITextView, ie I don't think it tells you where it's scrolled to, if it's scrolled at all. The underlying UIScrollView isn't exposed. I think if you want to reliably get that information you need to write your own subclass of UIScrollView to display text.

Note:

It does bother me a bit that both UIScrollView and UITextView (which inherits from it) both have a delegate property and it's of a different type in each class (id<UIScrollViewDelegate> vs id<UITextViewDelegate>), I thought if you subclassed something and tried to change the type of one of its properties, you got a compiler warning.


On Nov 2, 2008, at 12:23 AM, Ignacio Enriquez wrote:

Hello everyone,

I am quite new in implementing Delegates protocols and assignating
them. And I am having some kind of problems here.

I am trying to get the exact position of a text (using offset method
of UITextView) when scrolled
for that reason I have decide to adopt UIScrollViewDelegate and
implemented , let's say -
(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

And at the same time I have to be able to respond to touches. That's
is why I have decided to subclass UITextView , a class named
EVLessonTextView, and write touch methods like -
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event inside
there.

And a text view controller class that has some info like, the text to
be shown, the current text position and whether text viewer has been
touched or not.

The problem is, my app does not respond as expected. I think is has
something to be with assignation of delegates.
This a short version of what I wrote. But I hope I can learn from this.

Could you tell me what am I mistaking in?

// text view
@interface EVLessonTextView : UITextView {
        NSNumber * currentPosition;
}

@end
@implementation EVLessonTextView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event        
{
        NSLog(@"Ouch!!, text has been touched");
        [super touchesBegan:touches withEvent:event];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
        NSLog(@"view didScroll!!, current position has been calculated");
}

//text view controller
@interface EVTextViewController : UIViewController
<UITextViewDelegate, UIScrollViewDelegate> {
        IBOutlet EVLessonTextView * textView;
        NSNumber *currentTextPosition;
        Boolean *textHasBeenTouched;
}

- (void)viewDidLoad {
   [super viewDidLoad];
        
        textView.delegate = textView;     // GETS A WARNING here,
EVLessonTextView does not implement UITextViewDelegate protocol
        textView.text = @"super ultra long scrollable text content";

        textView.editable = NO;
        
}


in the part I get a warning, If write
textView.delegate = textView
then only scroll methods works fine, but I have a warning

if I change it to
textView.delegate = self
then I got nothing, not warning, but not scrolling methods and not
even touches methods.

What is wrong?
I am kind of stacked here.

Thanks in advance for your help.

Ignacio
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to