maraki
maraki

Reputation: 69

Change label with button

I have no idea how I can get stuck on this simple thing, but I can't get my button to change my label. What have I missed?

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

Upvotes: 0

Views: 70

Answers (3)

mzouink
mzouink

Reputation: 517

I think it's a problem of a connection between button and function try to click CTRL and drag the button to the function code to link them

Upvotes: 1

Herbert Hu
Herbert Hu

Reputation: 1

  1. Whether quoteButtonPressed: method is executed. You can try to make a breakpoint at the line of -(void)quoteButtonPressed: method. Then you run the project again, see Whether the project stops at the breakpoint line.

  2. Did IBOutlet connect well? There is any warnings about connections.

  3. Lengthen quoteLabel.

Upvotes: 0

SHEBIN
SHEBIN

Reputation: 162

you may not connect IBAction for button.or IBOutlet connection for label to interface builder.check it

Upvotes: 1

Related Questions