0

I am really new to iOS programming. I am just trying to make a button click event and when I run simulator an exception comes up

2014-10-27 12:00:00.859 practiceapp[682:28288] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7f95fb721120> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button1.'

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextField *textfield;
@property (weak, nonatomic) IBOutlet UIButton *button;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

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

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

- (IBAction)changebuttonaction:(id)sender {

    NSString *st = self.textfield.text;
    self.label.text=st;
    [self.textfield resignFirstResponder];
}



@end

You can find the source here: https://github.com/liaoxsong/practiceapp

4

2 回答 2

3

异常消息说明了一切。您的 Storyboard/IB 连接设置为名为的插座,该插座button1不存在。您的属性名为button

要更正此问题,您需要删除情节提要或 xib 文件中的损坏链接,并将 UIButton 的引用插座重新连接到button

于 2014-10-27T17:10:49.207 回答
2

您有三个具有无效连接的不同视图。如果您查看视图控制器的连接检查器,您会发现 button1、label1 和 textField1 无效。这些被列为!。

在这里仔细查看图片。 在此处输入图像描述

如果您通过单击 X 按钮从连接检查器中删除 button1、label1 和 textField1 连接,那么您应该很高兴。

于 2014-10-27T17:12:30.490 回答