带有添加按钮的基于导航的应用程序
我创建了一个新的基于导航的应用程序项目。然后在 MainWindow.xib 中我向导航栏添加了一个按钮。我想将一个新视图推送到屏幕上,我可以在其中输入信息,该信息将作为对象添加到 UITableView 的数组中。
但我不知道在哪里编写 IBAction 将按钮链接到(Appdelegate 或 RootViewController)?因为正如您在屏幕截图中看到的,它驻留在 MainWindow.xib 中,因为 RootViewController 只是一个表并且不包含导航。但在 MainWindow.xib 的文档视图中,它位于 RootViewController 下。
我是否还必须在 XIB 内创建一个新的视图控制器并为其创建一个 IBOutlet?
我尝试将代码放入我的 AppDelegate 并将按钮引用给委托,但它不起作用。
请帮忙。提前致谢。
请参阅此处的屏幕截图:http://i56.tinypic.com/5djbcm.png
I created a new Navigation Based Application project.Then in MainWindow.xib I added a button to the navigationbar. I would like to push a new View onto the screen where I can enter information, which will be added as an object to the array of the UITableView.
But I don't know where to write the IBAction to link the button to (Appdelegate or the RootViewController)? Because as you see in the screenshot, it resides in MainWindow.xib because the RootViewController is merely a Table and doesn't contain the navigation. But in the document view of MainWindow.xib it is located under the RootViewController.
Do I have to create a new View Controller inside the XIB as well and create an IBOutlet for it?
I tried putting the code inside my AppDelegate and reference the button to the delegate but it doesn't work.
Please help. Thanks in advance.
See the screenshot here: http://i56.tinypic.com/5djbcm.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您问自己一个问题“这个操作属于哪里”时,它很可能是一个控制器,因为控制器处理您应用程序中的事件流。下一个问题 - “当此操作发生时,哪个控制器负责?哪个控制器对此操作最感兴趣?”。您的情况的答案是根表控制器(
RootViewController
实例)。在其中创建一个 IBAction 方法,它将表单控制器(用于输入信息的控制器)推送到导航控制器。When you ask yourself a question "where does this action belong" it's most probably a controller because controllers handle event flows in your app. Next question - "What controller is in charge when this action happens? What controller is most interested in this action?". Answer in your case is root table controller (
RootViewController
instance). Create anIBAction
method in it which will push form controller (one you use to enter information) to navigation controller.