如何使用故事板添加自定义数据源类 [英] How to add custom data source class using storyboard

查看:166
本文介绍了如何使用故事板添加自定义数据源类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在故事板中添加我的自定义数据源类UICollectionView的方法。数据源类有这样的接口:

I can't find the way to add my custom data source class of UICollectionView in the storyboard. The data source class has an interface like this:

@interface CalendarDataSource : NSObject<UICollectionViewDataSource>

我试图在场景边栏中找到日历数据源,但我不能。所以我似乎无法将类链接到我的UICollectionView。有什么我应该做但我没有吗?

I try to find the calendar data source in the scene sidebar but I can't. So I can't seem to link the class to my UICollectionView. Is there something I should do but I didn't?

如果你想重现类似的问题,只需创建一个在XCode5中的新项目,设置一个UICollectionViewController,并像上面一样创建一个新类。

If you want to reproduce the similar problem, just create a new project in XCode5, set up a UICollectionViewController, and create a new class just like above.

我正在重写 http://www.objc.io/issue-3/ Github回购 https://github.com/objcio/issue-3-collection-view-layouts 这个项目成功了然而,这。我的代码与项目几乎相同但无法运行,因为viewcontroller.collectionView.dataSource未初始化。

I'm currently rewriting the project described in http://www.objc.io/issue-3/ The Github repo is https://github.com/objcio/issue-3-collection-view-layouts This project managed to do this, however. My code is almost the same to the project but can't run because viewcontroller.collectionView.dataSource is uninitialized.

以编程方式进行初始化是另一个问题,但请在评论中告诉我,因为我从互联网上获得的只是将dataSource设置为self。但是将它设置为self并不需要引入一个新的保留数据源对象,我被卡住了。

Doing the initialisation programmatically is another issue, but please tell me in the comment because all I got from the internet is setting dataSource to self. But setting it to self doesn't require introducing a new retained data source object, which I got stuck on.

推荐答案

转到界面生成器。


  • 右键单击故事板中的集合视图,删除 dataSource outlet(如果有的话)。

  • 在对象库的搜索文本字段中键入对象,然后将对象拖到包含UICollectionView的视图控制器中(即执行相同操作)您将任何视图或视图控制器添加到情节提要场景,除了您不添加视图或视图控制器而是添加抽象对象)。

  • 在您的左侧场景面板中故事板,突出显示刚刚添加的对象;在右侧面板中,转到Identity Inspector并键入 CalendarDataSource ,而不是预定义的 NSObject 。在左侧面板('场景')中,'对象'将自动重命名为'日历数据源'。

  • 在故事板的左侧场景面板中,控制 - 从您的UICollectionView拖动到'日历数据源';在弹出窗口中,选择 dataSource outlet。

  • Right-click on your Collection View in the storyboard, delete dataSource outlet (if any).
  • Type "Object" in the search text field of the Objects Library and drag an 'Object' to your view controller containing UICollectionView (i.e. do the same as you add any view or view controller to storyboard scene, with the exception you add not a view or view controller but an abstract object).
  • In the left-side 'Scenes' panel of your storyboard, highlight just added Object; in right-side panel go to the 'Identity Inspector' and type CalendarDataSource instead of pre-defined NSObject. In left side panel ('Scenes'), 'Object' will be renamed to 'Calendar Data Source' automatically.
  • In the left-side 'Scenes' panel of your storyboard, control-drag from your UICollectionView to the 'Calendar Data Source'; in pop-up appeared, select dataSource outlet.

你已经完成了!

这篇关于如何使用故事板添加自定义数据源类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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