ios - 按钮点击事件的 NSUnknownKeyException

标签 ios objective-c nsunknownkeyexception

<分区>

我真的是 iOS 编程的新手。我只是想制作一个按钮点击事件,当我运行模拟器时出现异常

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

您可以在这里找到来源:https://github.com/liaoxsong/practiceapp

最佳答案

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

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

关于ios - 按钮点击事件的 NSUnknownKeyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26592931/

上一篇:ios - 具有相同 segueIdentifer 的多个按钮

下一篇:iOS - 代表不工作

相关文章:

objective-c - 多个 View Controller 中的 CLLocation

ios - 一个带有两个导航栏的 Controller

ios - Xamarin.Forms 和 iOS : how to combine UseSafeArea and a background image?

ios - 此类对于键 storyboardName 不符合键值编码

ios - 线程 1 : signal SIGABRT Login Button Causes App to Crash

ios - tableViewCell 中的行在滚动时改变它们的位置

iphone - 正确分配/取消分配 UINavigationControllerDelagate

iphone - 允许iphone在更新ui时休眠

objective-c - 如何将数组的元素传递给可变参数函数?

ios - 在 Swift 中处理未捕获的异常 valueForUndefinedKey