简体   繁体   English

IBAction不能设置为按钮

[英]IBAction cannot be set to a button

So following http://www.techotopia.com/index.php/Creating_an_Interactive_iOS_4_iPhone_App , I'm doing the tutorial in a tabbed application template which the same thing, I have a button in the FirstViewController.xib and in the .h file, i declared a -(IBAction) selectedRow; 因此,按照http://www.techotopia.com/index.php/Creating_an_Interactive_iOS_4_iPhone_App进行操作时 ,我正在使用选项卡式应用程序模板来进行本教程,同样,在FirstViewController.xib和.h文件中都有一个按钮,我声明了-(IBAction)selectedRow; which by clicking i'm suppose to show an alert to the user. 通过单击我想向用户显示警报。 But the problem comes from the IB where I can't right click drag, or ctrl drag or even drag the event to the File's Owner to see the action. 但是问题出在IB上,我无法右键单击拖动,或Ctrl拖动甚至将事件拖动到“文件的所有者”以查看操作。 If I do this in a single view application, it works! 如果我在单视图应用程序中执行此操作,那么它将起作用! am i missing something here? 我在这里想念什么吗?

First of all, just for convention, make your IBAction method names sound like actions. 首先,仅出于约定,使IBAction方法名称听起来像动作。 For example, - (IBAction)selectRow:(id)sender; 例如, - (IBAction)selectRow:(id)sender;

Convention aside, you're missing IBActions require a parameter of type id as I did in my example above. 除了约定,您缺少IBAction,它需要一个id类型的参数,就像我在上面的示例中所做的那样。 Otherwise, that action won't be available to you in IB. 否则,您在IB中将无法使用该操作。

I think the file's owner class is not set, so IB doesn't know which is the view controller and what are its actions. 我认为未设置文件的所有者类,因此IB不知道哪个是视图控制器以及它的操作是什么。

Modify the Class parameter in file's owner from UIViewController into FirstViewController , to the correct name of your view controller. 将文件所有者中的Class参数从UIViewControllerFirstViewController ,以使用您的视图控制器的正确名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM