当我尝试在单击按钮时更改标签的文本时,代码会编译,但无法正常工作。我单击按钮,没有任何反应。目前,我只是试图在按下按钮resolveButton时在标签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
谢谢
您正在使用errorLabel而不是x1Label进行书写。
您是否将SolveButton操作连接到情节提要中的按钮?如果不是,请转到情节提要>单击您的按钮>转到“连接检查器”(在右侧面板上),然后将操作链接到您的按钮。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句