我正在尝试一起遵循 iTunes U 课程编码,其中涵盖了 Objective C。当我编译第一个代码时,它构建时没有错误,但是当它运行时,我收到一个错误,显示 Thread 1: SIGABRT。在主文件中
//
// main.m
// Card
//
// Created by Sid Muthal on 6/25/13.
// Copyright (c) 2013 SidMuthal. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "CardGameAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CardGameAppDelegate class]));
}
}
它出现在读取 return UIApplicationMain(argc, argv, nil, NSStringFromClass([CardGameAppDelegate class])); 的行上。
当我使用 GDB 调试器时,它给出了导致此崩溃的以下原因
2013-07-14 14:08:46.052 Matchgame[3148:c07] * 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类与键 Card_button 的键值编码不兼容。* First throw call stack: (0x1c94012 0x10d1e7e 0x1d1cfb1 0xb7de41 0xaff5f8 0xaff0e7 0xb29b58 0x233019 0x10e5663 0x1c8f45a 0x231b1c 0xf67e7 0xf6dc8 0xf6ff8 0xf7232 0x463d5 0x4676f 0x46905 0xcd6eab6 0x4f917 0x1396c 0x1494b 0x25cb5 0x26beb 0x18698 0x1befdf9 0x1befad0 0x1c09bf5 0x1c09962 0x1c3abb6 0x1c39f44 0x1c39e1b 0x1417a 0x15ffc 0x20ed 0x2015) libc++abi.dylib : 终止调用抛出异常
我的视图控制器似乎有问题。下面是我用于游戏控制器的代码。
//
// CardGameViewController.m
// Card
//
// Created by Sid Muthal on 6/25/13.
// Copyright (c) 2013 SidMuthal. All rights reserved.
//
#import "CardGameViewController.h"
@interface CardGameViewController ()
@property (weak, nonatomic) IBOutlet UILabel *flipsLabel;
@property(nonatomic) int flipCount;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *cardButton;
@end
@implementation CardGameViewController
-(void)setFlipCount:(int)flipCount
{
_flipCount = flipCount;
self.flipsLabel.text = [NSString stringWithFormat:@"Flips: %d", self.flipCount];
}
- (IBAction)flipCard:(UIButton *)sender
{
sender.selected = !sender.selected;
self.flipCount++;
}
@end
下面是h文件。
//
// CardGameViewController.h
// Card
//
// Created by Sid Muthal on 6/25/13.
// Copyright (c) 2013 SidMuthal. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CardGameViewController: UIViewController
@end
我已经为此苦苦挣扎了一段时间,所以任何帮助将不胜感激。我还是 Objective C 的新手。谢谢。