简体   繁体   English

iOS无法在View Controller中删除IBOutlet

[英]iOS Can't Drop IBOutlet in View Controller

First, I want to apologize if my question isn't asked properly or if the answer is obvious, but I'm learning iOS development and I have some difficulties with specific terms because I'm French. 首先,如果我的问题没有得到正确解答或者答案是否明显,我想道歉,但我正在学习iOS开发,而且由于我是法语,我在特定条款方面遇到了一些困难。

My application has a table view controller containing table view cells, and all of those contain a label and a switch. 我的应用程序有一个包含表视图单元格的表视图控制器,所有这些控制器都包含一个标签和一个开关。 It's made for my home automation: when I tap on a switch, it should switch on/off my lights or TV by sending an SSH command to a Raspberry Pi. 它是为我的家庭自动化做的:当我点击一个开关时,它应该通过向Raspberry Pi发送SSH命令来打开/关闭我的灯或电视。

So here is my problem: I followed a tutorial on Treehouse to add an action to my switch, but when I an action from storyboard to the view controller, then drop in between @interface and @end , nothing is generated, and I would like to know why. 所以这是我的问题:我按照Treehouse上的教程向我的交换机添加一个动作,但是当我从故事板到视图控制器的动作,然后在@interface@end之间插入,没有生成任何内容,我想知道为什么。

PS: Can someone tell me where all my objects contained in my view are declared, because when I right-click on my storyboard and then open as source code, it's an XML file. PS:有人可以告诉我视图中包含的所有对象都在哪里声明,因为当我右键单击我的故事板然后打开源代码时,它就是一个XML文件。 Why they are not in Obj-C? 为什么他们不在Obj-C?

Thanks. 谢谢。

Objective-C is a fully reflective language: from the string name of a class and the string name of a method you can, at runtime, create an instance of that class and call that method. Objective-C是一种完全反射的语言:从类的字符串名称和方法的字符串名称,您可以在运行时创建该类的实例并调用该方法。

The interface builder is a design tool. 界面构建器是一种设计工具。 You lay out views and give them properties. 您可以布置视图并为其提供属性。 It's essentially a drawing tool so just like Photoshop or whatever its documents are pure data . 它本质上是一个绘图工具,就像Photoshop或其文档是纯数据一样 It happens to store those in XML. 碰巧用XML存储它们。

The data is parsed and converted into objects in the same way that a PNG file might be parsed and turned into pixels. 数据被解析并转换为对象,其方式与解析PNG文件并转换为像素的方式相同。 So no code is generated . 所以没有生成代码 This is not like Visual C++ or one of those that sort of hacks on a design tool by automatically generating code. 这与Visual C ++不同,或者通过自动生成代码来破解设计工具。 There is no code. 没有代码。 You can't see it because it never exists, anywhere. 您无法看到它,因为它永远不会存在于任何地方。

As it happens the interface files are currently a particular format of XML. 碰巧接口文件目前是XML的特定格式。 They've been other forms in the past. 他们过去曾是其他形式。 It's undocumented and not to be relied on directly. 它没有记录,不能直接依赖。 Just use UINib to read them, or rely on that happening automatically through the main interface file you've possibly specified in your Info.plist. 只需使用UINib读取它们,或者通过您可能在Info.plist中指定的主界面文件自动依赖它。

As to the tutorial, it's difficult to answer without seeing the project. 至于教程,没有看到项目就很难回答。 Is the view controller you're dragging to definitely the type named in the interface file? 视图控制器是否正在拖动到接口文件中指定的类型?

If your table view is set to be dynamic using prototype cells, I don't think you can drag a component from the prototype cell onto your ViewController. 如果使用原型单元格将表视图设置为动态,我认为您不能将组件从原型单元拖到ViewController上。 Instead, you want to create a custom table view cell class. 相反,您想要创建自定义表视图单元类。 Then you would assign your prototype cell with the switch to use your custom class. 然后,您将使用开关分配原型单元格以使用您的自定义类。 Finally, you should be able to control-drag the switch onto your custom cell class and create an outlet property. 最后,您应该能够控制 - 将开关拖到自定义单元类上并创建出口属性。 This will give you a reference to the switch for each cell. 这将为您提供每个单元格的开关参考。 In your view controller, you can then obtain the cell object and then get the switch property. 在视图控制器中,您可以获取单元对象,然后获取switch属性。 The same goes for adding an action, you can control drag the action to your custom cell class. 添加动作也是如此,您可以控制将动作拖动到自定义单元类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM