[英]Getting iOS outlets wired in InterfaceBuilder
I'm new to developing in iOS and successfully ran through a tutorial on how to create and connect outlets in a Mac OSX Cocoa App. 我是iOS开发的新手,并且成功地完成了有关如何在Mac OSX Cocoa App中创建和连接插座的教程。 However, when I try to follow the same process for my iPhone app, I keep hitting walls... (Apologies for the lengthy example- please bear with) 但是,当我尝试对我的iPhone应用程序执行相同的过程时,我总是碰壁...(冗长的示例表示歉意,请耐心等待)
Project A: 项目A:
In xCode: 在xCode中:
Create a new class 创建一个新的班级
SimpleViewController : NSObject
#import <Cocoa/Cocoa.h>
@interface SimpleViewController : NSObject {
IBOutlet NSTextField *aField;
IBOutlet NSButton *aButton;
}
@end
In Interface Builder: 在界面生成器中:
SimpleViewController
from my library into the main.nib 将SimpleViewController
从我的库拖到main.nib中 SimpleViewController
to view elements to connect my outlets Ctl从SimpleViewController
拖动以查看元素以连接我的插座 Everything above works great. 上面的一切都很好。 Now for the same thing in an iPhone app: 现在,对于iPhone应用程序中的同一件事:
Project B: 项目B:
In XCode: 在XCode中:
Create a new class 创建一个新的班级
SimpleViewController : UIViewController
#import <UIKit/UIKit.h>
@class NSTextField;
@class NSButton;
@interface EmbedComplexViewController : UIViewController {
IBOutlet NSTextField *aField;
IBOutlet NSButton *aButton;
}
@end
(Notice my view controller is now an extension of UIViewController
, not NSObject
. Also, this time I need to use forward class declarations for my outlet classes. Not a problem, but is this necessary?) (请注意,我的视图控制器现在是UIViewController
的扩展,不是NSObject
的扩展。此外,这一次我需要对出口类使用正向类声明。这不是问题,但这是否有必要?)
In Interface Builder: 在界面生成器中:
SimpleViewController
from my library into the main.nib 将SimpleViewController
从我的库拖到main.nib中 SimpleViewController
to view
elements - BUT now I can't see any of my declared outlet member variables. Ctl从SimpleViewController
拖动以view
元素-但现在我看不到任何已声明的插座成员变量。 Instead, the only outlet option I have is 'view' 相反,我唯一的出口选择是“查看” What more do I need to do to have my declared outlets show up? 我需要做些什么才能显示已声明的店铺?
Thanks- Yarin 谢谢-Yarin
In iOS development, we use UIButton
and UITextField
and etc, (see the iphone developer documentation). 在iOS开发中,我们使用UIButton
和UITextField
等(请参阅iphone开发人员文档)。
And no, you don't need to forward declare those classes (it made you since they weren't included in UIKit 不,您不需要转发声明这些类(因为您没有将它们包含在UIKit中,所以使您成为了类)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.