ios - Xcode 更新到 4.5 版后按钮不起作用

标签 ios xcode button ibaction xcode4.5

我已经更新了我的 Xcode,但突然间所有在 Storyboard中连接到选择器的按钮都不再工作了。所有以编程方式编码的按钮和手势识别器都可以工作。部分原因是它们调用了相同的 IBAction。

我做了什么...

只需在 Storyboard 中的 View 中添加一个按钮和一个标签。在 View Controller .h 中,我向 Label 添加了一个 Outlet 并声明了 IBAction。 文件:

.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *myLabel;

-(IBAction)button_pressed:(id)sender;
-(IBAction)swipe_active:(id)sender;

@end

.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize myLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UISwipeGestureRecognizer *swipe_left = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe_active:)];
    swipe_left.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:swipe_left];
}

-(IBAction)button_pressed:(id)sender{
    myLabel.text=@"Button is Running";
}
-(IBAction)swipe_active:(id)sender{
    myLabel.text=@"Swipe is Running";
}

@end

只有按钮不起作用。

Storyboard:/image/1hruM.png

最佳答案

升级到 xcode 4.5 后,我遇到了同样的问题。 IBActions 看起来好像它们在 IB 中设置正确,但如果您查看 .h 和 .m 文件,您会发现它们不是。如果你转到你的 Storyboard并单击你的 View Controller ,请查看导出下方,你将看到“已接收操作”的选项卡。将您的控件连接到您的操作,它们将再次起作用。

关于ios - Xcode 更新到 4.5 版后按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12529137/

相关文章:

ios - 无法从 Alamofire 的 Swift 3 中的 Web 服务 PATCH API 调用获得响应

jquery - 向 jQuery Accordion 脚本添加关闭按钮

ios - 在 WKWebView 中禁用缩放?

xcode - 安装 cocoapods 对项目有何影响?

ios - 如果未安装应用程序,是否可以使用通用链接将用户重定向到特定内容?

iOS 11 中断( ionic )应用程序

ios - 尝试 segue SWIFT 时出现 lldb 错误

vba - 在运行时向工作表添加命令按钮并定义事件

ios - 如何从 Swift 中访问 CLLocationManager?

c# - 如何调用 method_getImplementation 的 IntPtr 结果