一个看似非常基本的问题,但它让我无休止地沮丧并阻碍了进步。当我从 UIButton
或 UIStepper
单击并拖动到 View Controller 时,未列出添加 IBAction
连接的选项。
View Controller 称为 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;
在 BuyNowVC.m
中:
@synthesize buyButton;
@synthesize myStepper;
- (IBAction)buttonPressed {
NSLog(@"Button pressed!");
}
- (IBAction)stepperPressed {
NSLog(@"Stepper pressed!");
}
我绝对是 ctrl 拖动到 View Controller 本身,但我使用 UIButton
和 UIStepper
获得的唯一选项是 Action Segue:推送、模态、自定义。没有 buttonPressed
或 stepperPressed
的迹象。
编辑
我还应该提一下,这不是根 VC,UIButton
当前绑定(bind)到下一个 View Controller 的 Segue(因此我可以导航我的模型)但它似乎没有如果我删除它会有所作为。
最佳答案
首先,BuyNow.m
应该是BuyNowVC.m
吗?
其次,如果您尝试将 UIButton
绑定(bind)到 View Controller 中的 IBAction
,并且如果这不起作用,您可能错过了使用您尝试将 UIButton
连接到 Storyboard中的 View Controller 的名称重命名“自定义类”字段。
第三,您提到了“....是Action Segue:push
、modal
、custom
。没有 buttonPressed
或 stepperPressed
的迹象。”。此信息告诉我您正在尝试control 将您的UIButton
拖到另一个 View Controller 上,您尝试将IBAction 绑定(bind)到该 View Controller 上
那是不可能的。
添加屏幕截图:
请在 Storyboard中查看此处:
您已将 UIButton
的“自定义类”名称更改为您自己的按钮名称。
请将其改回 UIButton
作为“自定义类”字段的名称。
查看屏幕截图:
不要像图片中那样做。将其改回 UIButton
。完成此操作后,您将看到“Action Connection”在 control 上再次向您挥手“嗨”- 拖动到它。
步骤:
1.) 在 Storyboard 中的 View Controller 上单击您的 UIButton
。
2.)检查右侧面板(左数第 3 个选项卡)并将“自定义类”字段更改回 UIButton
。
所以应该是:
关于ios - 无法在 Xcode 5 Storyboard 中创建 IBAction 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21602260/