2013-10-12 56 views
1

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

.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 

谢谢

+0

写下这样每个对象的前自我: - “self.aField” –

+0

正确检查您的IBOutlet中,并尝试与self.errorLabel.text = @“错误”; –

+0

我应该在哪里写self.aField ..它应该怎么做? – Sam

回答

0
  1. 你是不是在x1Label写上errorLabel。

  2. 您是否将SolveButton动作连接到故事板中的按钮? 如果不去故事板>单击按钮>转到连接检查器(位于右侧面板)并将操作链接到您的按钮。

+0

感谢您的快速响应。它是否真的很重要,因为我只是想让它工作,它是否会出现错误标签或x1标签。另外,我似乎无法在我的右侧面板上找到连接检查器。但是,我的按钮位于连接到“视图控制器” – Sam

+0

屏幕截图的引用插座中,以使其更加难以理解:http://i.imgur.com/99nttUe.png – Sam

+0

您需要将操作连接到您的按钮,否则他不知道何时需要完成操作。连接Inspector位于右侧面板中,当您单击故事板时会看到该面板。有很多图标你正在寻找的是指向你的屏幕外部的箭头(最后一个在右边)。如果你仍然无法找到它谷歌它,看到图像:) – r4id4