我更新了我的 Xcode,突然所有在情节提要中连接到选择器的按钮都不再工作了。所有以编程方式编码的按钮和手势识别器都可以工作。部分原因是,他们调用了相同的 IBAction。
我做了什么...
只需在情节提要中的视图中添加一个按钮和一个标签。在 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
而且只是按钮不起作用。