iPhone:我是否需要实现UIScrollViewDelegate(或任何委托)的所有方法 [英] iPhone: Do I need to implement all methods for UIScrollViewDelegate (or any delegate)

查看:46
本文介绍了iPhone:我是否需要实现UIScrollViewDelegate(或任何委托)的所有方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我将UIViewController设为UIScrollViewDelegate.

Suppose I make a UIViewController a UIScrollViewDelegate.

我是否需要为委托实现所有方法,还是可以仅实现我所关心的1个方法?

Do I need to implement all methods for the delegate, or can I just implement the 1 I care about?

推荐答案

如果您在声明要实现协议的xcode中 cmd +单击

If you cmd + click in xcode where you have declared that you implement the protocol

<UIScrollViewDelegate>

Xcode将带您到定义协议的头文件.在这里,您可以看到 UIScrollViewDelegate 的所有方法都声明为 @optional ,因此您可以实现所需的方法.

Xcode will take you to the header file where the protocol is defined. Here you can see that all of the methods for UIScrollViewDelegate are declared as @optional therefore you can just implement the ones you want.

如果您喜欢文档,则 Apple Tasks 部分中用必需的方法标记所需的方法.

If you prefer the documentation then Apple marks the required methods with required method in the Tasks section.

另外,如果您说您遵守协议但未实现必需的方法,则编译器将显示警告.

Additionally the compiler will show warnings if you say you conform to a protocol but do not implement required methods.

这篇关于iPhone:我是否需要实现UIScrollViewDelegate(或任何委托)的所有方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆