1

当我尝试在单击按钮时更改标签的文本时,代码会编译但它不起作用。我单击按钮,没有任何反应。目前,我只是试图在按下按钮solveButton时在标签x1Label上显示“错误”。你能帮我修一下吗?

。H

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize errorLabel;
@synthesize aField, bField, cField;
@synthesize x1Label, x2Label;
@synthesize solveButton;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    aField.delegate = self;
    bField.delegate = self;
    cField.delegate = self;

    aField.keyboardType = UIKeyboardTypeNumberPad;
    bField.keyboardType = UIKeyboardTypeNumberPad;
    cField.keyboardType = UIKeyboardTypeNumberPad;

    NSString *str = @"car";
    errorLabel.text = str;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    [aField resignFirstResponder];
    [bField resignFirstResponder];
    [cField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [aField resignFirstResponder];
    [bField resignFirstResponder];
    [cField resignFirstResponder];
}

- (IBAction)solveButton:(id)sender
{
    errorLabel.text = @"Error";
}

@end

.m

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextFieldDelegate>
{
    IBOutlet UITextField *aField, *bField, *cField;
}

@property (weak, nonatomic) IBOutlet UILabel *errorLabel;

@property (strong, nonatomic) IBOutlet UITextField *aField;

@property (strong, nonatomic) IBOutlet UITextField *bField;

@property (strong, nonatomic) IBOutlet UITextField *cField;

@property (weak, nonatomic) IBOutlet UILabel *x1Label;

@property (weak, nonatomic) IBOutlet UILabel *x2Label;

@property (weak, nonatomic) IBOutlet UIButton *solveButton;

@end

谢谢

4

1 回答 1

0
  1. 您在 errorLabel 上而不是在 x1Label 上书写。

  2. 您是否将 SolveButton 操作连接到情节提要中的按钮?如果没有转到情节提要>单击您的按钮>转到连接检查器(在右侧面板上)并将操作链接到您的按钮。

于 2013-10-12T13:02:22.090 回答