这是真的Xcode / IB不检查协议吗? [英] Is it true Xcode/IB DOES NOT check for protocols?

查看:101
本文介绍了这是真的Xcode / IB不检查协议吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅限Xcode5环境。 (不是旧版本。)

Xcode5 milieu only. (Not older versions.)

1)创建一个名为say test的新类。这是一个UIViewController

1) make a new class called say Test. it's a UIViewController

@interface Test:UIViewController

2)在故事板中,制作一个新屏幕,一个UIViewController,将其更改为测试

2) in storyboard, make a new screen, a UIViewController, change it to "Test"

显然,如果你添加故事板上的控件(例如,按钮),您可以将其拖动到Test.h中定义的IBOutlet。没问题。

obviously, if you add a control (say, a button) on the storyboard, you can drag it to an IBOutlet defined in Test.h. No problem.

3)现在在Test.h中添加两个协议..

3) Now in Test.h add the two protocols ..

@interface Test:UIViewController
          <
          UICollectionViewDataSource,
          UICollectionViewDelegateFlowLayout
          >

4)现在在IB中将一个小的UICollectionView拖入视图。

4) now in IB drag a small UICollectionView in to the view.

5)点击集合视图,连接检查器。现在,将委托和dataSource拖到测试

5) click on the collection view, connections inspector. now, drag the delegate and dataSource to "Test"

一切正常.. 没问题

然而。断开这些连接。回到步骤(3)。 不要执行第3步。换句话说,您已忘记将协议添加到测试中。

However. Disconnect those connections. Go back to step (3). Do not do step 3. in other words, you've "forgotten" to add the protocols to Test.

现在尝试步骤(5) )

Now try step (5)

事实上(我相信)......它运作正常。

我觉得你可以拖到一个UICollectionViewDataSource(比如说),实际上它根本就不是一个UICollectionViewDataSource(!)

It seems strange to me that you can drag to a UICollectionViewDataSource (say) when, in fact, it simply is NOT a UICollectionViewDataSource (!)

(当然,你可以在任何没有IBOutlet的地方都会拖动一个按钮。)

(Naturally, you can't drag, say, a button anywhere there is no IBOutlet.)

(A)其他人是否看到这种行为,我有没有像往常一样搞砸了?

(A) Does everyone else see this behaviour, of have I screwed up as usual?

(B)这可能是已知错误/遗漏吗?

(C)还有什么我想念的吗(哦,它必须是那样的因为......)

(C) Is there anything else I'm missing ("oh, it has to be like that because...")

干杯

推荐答案

是的,这是真的。 UIB不检查是否实现了任何协议方法。即使您在项目的构建设置中为不完整的Objective-C协议启用了警告,其行为也是相同的。

Yes, it's true. UIB does not check any protocol method is implemented. Even if you enabled warnings for Incomplete Objective-C Protocols in Build Settings for your project, its behaviour is the same.

这篇关于这是真的Xcode / IB不检查协议吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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