Objective C initWithNibName
我在弄清楚 Apple 教程中的这个函数代表什么时遇到了一些困难:
[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]
我的问题是:MyViewController 之前的“@”代表什么?
另外,因为我正在关注 this教程,我想知道:我的项目中有笔尖:自动生成的MainWindow.xib和MyViewController.xib - 我想知道:如果我只需要一个,为什么我有两个?
提前致谢!
I am facing some difficulties figuring out what this function in the Apple tutorials stands for:
[[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]
My questions are: what does the "@" stand for before MyViewController?
Addionally, as I am following this tutorial, I was wondering: There are to nibs in my project: the automatically generated MainWindow.xib and MyViewController.xib – I was wondering: why do I have two if I only need one?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字符串前面的 @ 符号表示该字符串是 NSString 的实例。
您甚至可以向它发送消息:
您将比 C 字符串更频繁地使用 NSString 对象。
如果您想将 C 字符串转换为 NSString 对象(例如,如果您使用返回此类字符串的 C 库),您可以使用以下内容:
关于两个笔尖:实际上您根本不需要任何笔尖,但是苹果喜欢通过使用只有一个窗口的笔尖来降低性能。我不知道他们为什么这样做,但你可以用一行代码创建一个窗口,这样编译和运行速度会快得多。
在您的
applicationDidFinishLaunching:
方法中:我个人更喜欢完全不使用笔尖,但这是个人的选择。
The @-sign before a string literal means that the string is an instance of NSString.
You can even send messages to it:
You will use NSString objects more often than C-strings.
If you want to convert a C-string to an NSString object (if you are using C libraries that return such strings for example), you could use this:
About the two nibs: actually you don't need any nibs at all, but Apple likes to decrease performance by using a nib that only has one window. I don't know why they do it, but you can create a window in code with only one line, which compiles and runs much faster.
In your
applicationDidFinishLaunching:
method:Personally I prefer to use no nibs at all, but that's one's own choice.