我已经更新了我的 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/