xcode 链接文件的所有者和视图控制器 [iPhone SDK]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/184985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking File's Owners and View Controller [iPhone SDK]
提问by mmalc
I seem to be having an issue with iPhone SDK 2.1 in as far as being
able to establish a relationship between a ViewController and a View
window. In as far as a Cocoa Touch Class, I went forward and added a
UIViewController
subclass. I made sure that the target is part of the
existing project. Right afterwards I added a User Interfaces -> View
XIB. Within the UIViewController
I have some straight forward code I
literally copy/pasted from sample code elsewhere:
就能够在 ViewController 和 View 窗口之间建立关系而言,我似乎遇到了 iPhone SDK 2.1 的问题。就 Cocoa Touch 类而言,我继续添加了一个
UIViewController
子类。我确保目标是现有项目的一部分。紧接着我添加了一个用户界面 - >查看XIB。在UIViewController
我有一些直接的代码中,我从其他地方的示例代码中复制/粘贴:
EditViewController.h:
编辑视图控制器.h:
@interface EditorViewController : UIViewController <UITextFieldDelegate> {
UITextField *field;
}
@property(nonatomic, retain) IBOutlet UITextField *field;
@end
EditViewController.m
编辑视图控制器.m
#import "EditorViewController.h"
@implementation EditorViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)dealloc {
[super dealloc];
}
@end
As you can tell, it doesn't do much. Now when I click my new xib, and
reference a class identity with EditorViewController
, no auto complete
happens, which to me implies that it has no such awareness of a
EditorViewClass
. When I attempt to control+click from the view to
File's Owners, I get nada.
正如你所知道的,它没有多大作用。现在,当我单击我的新 xib 并使用 引用类标识时EditorViewController
,不会发生自动完成,这对我来说意味着它没有这样的
EditorViewClass
. 当我尝试从视图控制+单击到文件所有者时,我得到了 nada。
What are some of the possible idiosyncrasies in this process that I'm overlooking that's not allowing me to outlet my view to a controller?
在这个过程中我忽略了哪些可能的特质,这些特质不允许我将我的观点输出给控制器?
How would I also ensure that my User Interface View XIB is associated with the project besides seeing the project name checked off as a Target?
除了查看项目名称作为目标勾选之外,我还如何确保我的用户界面视图 XIB 与项目相关联?
回答by mmalc
(This doesn't appear to be specific to iPhone -- it's a general class of problem for any platform.)
(这似乎不是 iPhone 特有的——它是任何平台的一般问题。)
It's barely clear what this means: "Now when I click my new xib, and reference a class identity with EditorViewController, no auto complete happens, which to me implies that it has no such awareness of a EditorViewClass."
几乎不清楚这意味着什么:“现在,当我单击我的新 xib,并使用 EditorViewController 引用类标识时,不会发生自动完成,这对我来说意味着它没有这样的 EditorViewClass 意识。”
Do you mean that you selected the File's Owner and tried to set its class to EditorViewController, but Interface Builder didn't autocomplete the class name for you?
您的意思是您选择了 File's Owner 并尝试将其类设置为 EditorViewController,但是 Interface Builder 没有为您自动完成类名?
If this is the case, is the xib file associated with the project?
如果是这种情况,xib 文件是否与项目相关联?
Other points that aren't directly relevant:
其他不直接相关的点:
Best practice is now that IBOutlet be associated with the property:
最佳实践是将 IBOutlet 与属性关联:
@interface EditorViewController : UIViewController
{
UITextField *field;
}
@property(nonatomic, retain) IBOutlet UITextField *field;
@end
You should also release the text field in dealloc
:
您还应该在dealloc
以下位置释放文本字段:
-(void)dealloc {
[textField release];
[super dealloc];
}
The formatting of your question makes it difficult to see what code you've written. The terminology is also "odd" -- outlet is not a verb:
您问题的格式使您很难看到您编写的代码。该术语也是“奇数”——outlet 不是动词:
"What are some of the possible idiosyncrasies in this process that I'm overlooking that's not allowing me to outlet my view to a controller?" do you mean: "Is there anything I may have overlooked that means I can't connect my controller's view outlet to the view in Interface Builder?"
“在这个过程中,我忽略了哪些可能的特质,这些特质不允许我将我的观点传达给控制器?” 你的意思是:“有什么我可能忽略了,这意味着我无法将控制器的视图出口连接到 Interface Builder 中的视图?”
回答by mmalc
It should be as simple as selecting the files owner and entering the name of your class in the class box (it should auto-complete and also be in the drop down menu). Make sure you arent trying to set the class to the view itself.
它应该像选择文件所有者并在课程框中输入课程名称一样简单(它应该自动完成并且也在下拉菜单中)。确保您没有尝试将类设置为视图本身。