是否可以在界面构建器中连接CustomViews的delegate和dataSource? [英] Is it possible to connect delegate and dataSource of CustomViews in interface builder?

查看:94
本文介绍了是否可以在界面构建器中连接CustomViews的delegate和dataSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在界面构建器中,如果我右键单击一个tableView,我会选择委托和dataSource出口,有时我们连接到文件的所有者,在大多数情况下是实现这些协议的View Controller,

In Interface builder, If I right click on a tableView, I get option of delegate and dataSource outlets which at times we connect to the file's owner which is in most cases the View Controller which implements these protocol,

我如何获得具有委托和数据源属性的自定义视图的类似选项?

How can I get a similar option for my custom view which has a delegate and a datasource property ?

推荐答案

您需要满足以下条件:


  1. 视图的自定义类应在Interface Builder中设置为自定义视图的类名(通过Identity Inspector)。如果您的委托或dataSource对象也是自定义视图,还要确保该视图的自定义类已设置

  2. @interface 您的自定义类应使用 IBOutlet 装饰其委托和dataSource属性。例如, @property(非原子,弱)IBOutlet id< SomeProtocol>委托;

  3. 如果您为委托或dataSource声明了协议,那么您要用作委托或dataSource的目标对象应声明为实施该协议

  1. The view's Custom Class should be set to your custom view's class name in Interface Builder (via the Identity Inspector). If your delegate or dataSource object is also a custom view, also make sure that that view's Custom Class is set
  2. The @interface for your custom class should decorate its delegate and dataSource properties with IBOutlet. For example, @property (nonatomic, weak) IBOutlet id <SomeProtocol> delegate;
  3. If you declared protocol(s) for your delegate or dataSource, the target object that you want to use as the delegate or dataSource should be declared as implementing that protocol

这篇关于是否可以在界面构建器中连接CustomViews的delegate和dataSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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