使用按钮更改标签

Change label with button

我不知道我怎么会卡在这个简单的事情上,但我无法按下更改标签的按钮。我错过了什么?

FirstViewController.h:

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *quoteButton;
@property (weak, nonatomic) IBOutlet UILabel *quoteLabel;

@end

FirstViewController.m:

#import "FirstViewController.h"

@implementation FirstViewController

#pragma mark - User Interaction

- (IBAction)quoteButtonPressed {
  self.quoteLabel.text = @"Hello World";
}

@end

您可能无法将 button.or 的 IBAction 连接到接口 builder.check 的 IBOutlet 连接

  1. 是否执行quoteButtonPressed:方法。 您可以尝试在 -(void)quoteButtonPressed: 方法行下断点。 然后你再运行工程,看工程是否停在断点行。

  2. IBOutlet 连接好了吗? 有任何关于连接的警告。

  3. 加长引用标签。

我认为是按钮和功能之间的连接问题 尝试单击 CTRL 并将按钮拖动到功能代码到 link 他们