ios – 在Xcode更新到4.5版之后Button不起作用

前端之家收集整理的这篇文章主要介绍了ios – 在Xcode更新到4.5版之后Button不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我更新了我的 Xcode,突然所有在故事板中连接到选择器的按钮都不再起作用了.所有以编程方式编码的按钮和手势识别器都可以工作.部分地,他们称同样的IBActions.

我做了什么…

只需在故事板中的视图中添加一个Button和一个Label.在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:@L_502_1@

解决方法

升级到xcode 4.5后,我遇到了同样的问题. IBActions看起来好像在IB中设置正确,但是如果你看一下.h和.m文件,你会发现它们不是.如果您转到故事板并单击视图控制器,请查看插座下方,您将看到“已接收操作”的选项卡.将控件连接到那里的操作,它们将再次工作.

猜你在找的Xcode相关文章