我正在使用在线 Treehouse 教程学习 Objective C 到目前为止,我已经一步一步地遵循了所有内容,并且在按下按钮时不断出现错误。我希望有人能告诉我我在这里做错了什么。到目前为止,应用程序应该在顶部有一个标签,在情节提要中间有一个按钮,当按下按钮时,它应该更改标签的文本。我的代码如下。
.m 文件
//
// ViewController.m
// Prediction
//
// Created by Brandon Brown on 7/7/13.
// Copyright (c) 2013 Brandon Brown. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize predictionLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setPredictionLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)buttonPressed:(id)sender {
self.predictionLabel.text = @"Yep";
}
@end
.h 文件
//
// ViewController.h
// Prediction
//
// Created by Brandon Brown on 7/7/13.
// Copyright (c) 2013 Brandon Brown. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)buttonPressed:(id)sender;
@property (strong, nonatomic) IBOutlet UILabel *predictionLabel;
@end
这是我在控制台中遇到的错误
2013-07-07 17:20:09.717 Prediction[14457:f803] -[UIView setText:]: unrecognized selector sent to instance 0x6a44690
2013-07-07 17:20:09.719 Prediction[14457:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setText:]: unrecognized selector sent to instance 0x6a44690'
*** First throw call stack:
(0x14b0022 0xeb0cd6 0x14b1cbd 0x1416ed0 0x1416cb2 0x22cf 0x14b1e99 0x1614e 0x160e6 0xbcade 0xbcfa7 0xbc266 0x3b3c0 0x3b5e6 0x21dc4 0x15634 0x139aef5 0x1484195 0x13e8ff2 0x13e78da 0x13e6d84 0x13e6c9b 0x13997d8 0x139988a 0x13626 0x1f0d 0x1e75)
terminate called throwing an exception