重构应用程序委托
我是 Obj-C 和 Xcode 4 的初学者,目前正在阅读 “您的第一个 Mac 应用程序”。我已经成功完成了主要部分,但我在“重构应用程序委托”部分中遇到了困难。
我创建了一个新类(用作控制器),添加了一个对象集到这个新类,建立了从类到滑块、静音按钮和文本字段的连接,并且我已将新类对象连接到应用程序委托接口文件。
不幸的是,轨道类的实例永远不会被创建,因此程序无法工作,因为 awakeFromNib 函数永远不会被调用。我尝试将它放在应用程序委托文件和新控制器类中。
我哪里错了???
I am a beginner to Obj-C and Xcode 4 and I am currently going through the "Your First Mac Application" on the Mac Dev website. I have managed to get through the main part but I'm struggling on the "Refactor the Application Delegate" section.
I have created a new class (to use as a controller), added an object set to this new class, made the connections from the class to the slider, mute button and textfield, and I have connected the new class object to the app delegate interface file.
Unfortunately an instance of the track class is never created, and therefore the program doesn't work, as the awakeFromNib function never gets called. I have tried placing it in both the app delegate file and the new controller class.
Where am I going wrong???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在 IB 中创建新类的实例,或者需要在 AppDelegate 对象中以编程方式创建它(通常在 init 或 awakeFromNib 中)。您需要在 AppDelegate 中有一个指向该对象的指针。如果您在 IB 中创建新对象,则将其连接到 IB 中的 Track* 指针。如果您在代码中执行此操作,则类似于:
在 .h 文件中:
在 .m 文件中:
您做了哪些操作?
You have to either create an instance of your new class in IB, or you need to create it programmatically in your AppDelegate object (usually in init or awakeFromNib). You need to have a pointer to that object in your AppDelegate. If you create the new object in IB, you connect it to the Track* pointer in IB. If you do it in code, it's something like:
in .h file:
in .m file:
Which did you do?
我在尝试本教程时遇到了同样的问题,发现问题出在我的
awakeFromNib
实现上错误的代码:
正确的代码
应该无参数传递<的实现代码>awakeFromNib。
I had the same issue while trying out the tutorial and found out the problem was with my implementation of
awakeFromNib
Wrong Code:
Right Code
There should be no argument passing the implementation of
awakeFromNib
.