无法在 Xcode 5 Storyboard 中创建 IBAction 连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21602260/
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
Can't create IBAction connections in Xcode 5 Storyboard
提问by Sebastian
A seemingly very basic problem, but it's frustrating me to no end and stalling progress. When I click and drag from a UIButton
or UIStepper
onto the View Controller, the option to add IBAction
connections aren't listed.
一个看似非常基本的问题,但它让我无休止地沮丧并阻碍了进展。当我单击并从 aUIButton
或拖动UIStepper
到视图控制器上时,IBAction
未列出添加连接的选项。
The View Controller is called BuyNowVC
and in my BuyNowVC.h
I have:
视图控制器被调用BuyNowVC
,在我的BuyNowVC.h
我有:
@interface BuyNowVC : UIViewController {
IBOutlet UIButton *buyButton;
IBOutlet UIStepper *myStepper;
}
@property (nonatomic, retain) IBOutlet UIButton *buyButton;
@property (nonatomic, retain) IBOutlet UIStepper *myStepper;
- (IBAction)buttonPressed;
- (IBAction)stepperPressed;
And in BuyNowVC.m
:
并在BuyNowVC.m
:
@synthesize buyButton;
@synthesize myStepper;
- (IBAction)buttonPressed {
NSLog(@"Button pressed!");
}
- (IBAction)stepperPressed {
NSLog(@"Stepper pressed!");
}
I'm definitely ctrl dragging onto the View Controller itself but the only options I get with both UIButton
and UIStepper
are Action Segue: push, modal, custom. No sign of buttonPressed
or stepperPressed
.
我肯定CTRL拖到视图控制器本身,而是唯一的选择,我得到两个UIButton
和UIStepper
的行动Segue公司:推,模式,自定义。没有buttonPressed
或 的迹象stepperPressed
。
Edit
编辑
I should also mention that this isn't the root VC and the UIButton
is currently tied to a Segue to the next View Controller (so I can navigate my mockup) but it doesn't seem to make a difference if I remove it.
我还应该提到,这不是根 VC,UIButton
它当前与下一个视图控制器的 Segue 相关联(因此我可以导航我的模型)但如果我删除它似乎没有什么区别。
回答by Unheilig
First, should BuyNow.m
be BuyNowVC.m
?
第一,应该BuyNow.m
是BuyNowVC.m
?
Second, if you are trying to tie an UIButton
to an IBAction
within your view controller and if that doesn't work, you might have missed re-naming the "Custom Class" field with the name of the view controller you try to connect the UIButton
to in storyboard.
其次,如果您试图将 an 绑定UIButton
到IBAction
您的视图控制器中,如果这不起作用,您可能错过了使用您尝试将其连接UIButton
到的视图控制器的名称重新命名“自定义类”字段故事板。
Third, you mentioned ".... are Action Segue: push
, modal
, custom
. No sign of buttonPressed
or stepperPressed
.". This information tells me that you are trying to controldrag your UIButton
onto anotherview controller, onto which you try to tie the IBAction
there - that is not possible.
第三,您提到“.... 是 Action Segue:push
,modal
,custom
. 没有buttonPressed
或 的迹象stepperPressed
”。此信息告诉我您正试图control将您的视图UIButton
拖到另一个视图控制器上,您试图将其绑定到IBAction
那里 - 这是不可能的。
Adding Screenshot:
添加截图:
Please check here in storyboard:
请在故事板中查看:
You have changed the "Custom Class" name for the UIButton
to your own button name.
您已将 的“自定义类”名称更改UIButton
为您自己的按钮名称。
Please change it back to UIButton
as name for "Custom Class" Field.
请将其改回UIButton
“自定义类”字段的名称。
See ScreenShot:
见截图:
Don't do this like in the image. Change it back to UIButton
. Once you have done so, you will see "Action Connection" waving "Hi" at you again upon control-Dragging to it.
不要像图片中那样做。将其改回UIButton
. 完成此操作后,您将看到“操作连接”在control拖动到它时再次向您挥手“嗨” 。
Steps:
脚步:
1.)Click on your UIButton
on your view controller in storyboard.
1.)UIButton
在情节提要中单击您的视图控制器。
2.)Check the right-hand side panel (3rd tab from left) and change the "Custom Class" Field back to UIButton
.
2.)检查右侧面板(左起第三个选项卡)并将“自定义类”字段更改回UIButton
。
So it should be:
所以应该是:
回答by Anthony Kong
It is how I normally do it:
这是我通常的做法:
While the storyboard is open,
当故事板打开时,
1) Select the middle icon ('Assistant')
1)选择中间的图标(“助手”)
2) Unselect the right pane
2)取消选择右窗格
3) Drag from the button to the ViewController editor while holding the control key. You will notice a small cocentric circle at line 10.
3) 按住 control 键的同时从按钮拖动到 ViewController 编辑器。您会注意到第 10 行有一个小的同心圆。
回答by Andy L.
Following on from the other answer... dragging into the @interface section of code gives you an outlet. Drag into the @implementation section to get an action.
继另一个答案之后......拖入代码的@interface 部分为您提供了一个出口。拖入@implementation 部分以获取操作。
Sorry I can't post the screen print. Not enough 'reputation' :(
对不起,我不能发布屏幕打印。没有足够的“声誉”:(