gpt4 book ai didi

iphone - 在 .m 上声明委托(delegate)

转载 作者:行者123 更新时间:2023-11-28 18:39:23 24 4
gpt4 key购买 nike

我对 Objective-C 比较陌生。

我在 rootViewController.m(这是一个基于 navigationController 的应用程序)上找到了类似这样的代码。

@interface RootViewController (CManagerDelegate) <CManagerDelegate>
@end

@interface RootViewController (PViewDelegate) <PViewDelegate>
@end

两个问题:

  1. rootViewController.m 开头的这些行是做什么的
  2. 这些行在代码中做了什么?在这种特殊情况下,请解释括号中和 <> 之间的内容。

谢谢。

最佳答案

一句话:您发布的代码使 RootViewController 类私下遵守一些委托(delegate)协议(protocol)。

委托(delegate)协议(protocol)用于让一个类声明它理解来自另一个类的对象的消息这一事实。例如, View Controller 可以声明它理解手势识别器的委托(delegate)消息。

该类在内部使用手势识别器这一事实通常是一个与该类的其他客户端无关的实现细节。最好不要在公共(public)接口(interface)中发布这个事实,而是将其放入实现(.m 文件)中。

类别(和类扩展)让您可以做到这一点:使类符合协议(protocol)而不更改主 @interface

一个漂亮而优雅的解决方案!

关于iphone - 在 .m 上声明委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13291198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com