简体   繁体   English

将UIScrollView委托设置为其自己的自定义类

[英]Set UIScrollView delegate to it's own custom class

I created a custom component from UIScrollView. 我从UIScrollView创建了一个自定义组件。

I create a custom UIScrollview class and add it to my scroll view. 我创建一个自定义UIScrollview类,并将其添加到滚动视图中。

And in the custom class in "- (void)drawRect:(CGRect)rect" I design my scroll view the way I wanted. 在“-(void)drawRect:(CGRect)rect”的自定义类中,我以所需的方式设计了滚动视图。 and its all working fine. 并且一切正常。

My Question is how to add my scrollview as the delegate of the Custom class. 我的问题是如何将滚动视图添加为Custom类的委托。

I did this inside my custom class - 我是在自定义类中完成此操作的-

self.delegate = self;

and the delegate get set and I have access to the UIScroll view delegate methods (like - - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView). 并设置了委托,我可以访问UIScroll视图的委托方法(例如--(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView)。

My problem is once I set my delegate like 'self.delegate = self;' 我的问题是,一旦我将代表设置为“ self.delegate = self;” compiler gives me a warning like below 编译器向我发出如下警告

在此处输入图片说明

Please can anyone help me to fix this warning. 请任何人帮我解决此警告。

You need to declare your custom class as conforming to the UIScrollViewDelegate protocol. 您需要将自定义类声明为符合UIScrollViewDelegate协议。

Check out the Apple docs on protocols . 查看有关协议Apple文档

In your header file, you probably have something like 在头文件中,您可能会遇到类似

@interface OGOTimeSelector : UIScrollView

To declare that your class conforms to the UIScrollViewDelegate protocol, this would become: 要声明您的类符合UIScrollViewDelegate协议,它将变为:

@interface OGOTimeSelector : UIScrollView <UIScrollViewDelegate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM