我正在通过在线视频课程学习iOS。我不确定为什么我会收到此错误。我觉得我一步一步地遵循了一切,我最终得到了这个错误:
通常我会查看错误和回溯以尝试查找错误发生的位置,但我是iOS的新手,我不理解输出。
2015-01-30 17:57:40.511 99RedBalloons[18322:1563170] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_9RedBalloons.ViewController 0x7fb5d3e17750> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key backgroundimageView.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ca3ff35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010e583bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ca3fb79 -[NSException raise] + 9
3 Foundation 0x000000010ce577b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010c989e80 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010d590c7d -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x000000010d3eff98 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x000000010d3f0588 -[UIViewController loadView] + 109
8 UIKit 0x000000010d3f07f9 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010d3f0c8e -[UIViewController view] + 27
10 UIKit 0x000000010d30fca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x000000010d310041 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x000000010d31c72c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x000000010d2c7061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
14 UIKit 0x000000010d2c9d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
15 UIKit 0x000000010d2c8bf2 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x00000001101102a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x000000010c97553c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x000000010c96b285 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x000000010c96aa43 __CFRunLoopRun + 851
20 CoreFoundation 0x000000010c96a486 CFRunLoopRunSpecific + 470
21 UIKit 0x000000010d2c8669 -[UIApplication _run] + 413
22 UIKit 0x000000010d2cb420 UIApplicationMain + 1282
23 99RedBalloons 0x000000010c4aacce top_level_code + 78
24 99RedBalloons 0x000000010c4aad0a main + 42
25 libdyld.dylib 0x000000010ed5d145 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
我不了解Traceback一位
代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var balloonsLabel: UILabel!
@IBOutlet weak var backgroundImageView: UIImageView!
var balloons:[Balloon] = [];
var currentIndex = 0;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.createBalloons()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func nextBalloonBarButtonItemPressed(sender: UIBarButtonItem) {
let balloon = balloons[currentIndex]
balloonsLabel.text = "\(balloon.number) balloon"
backgroundImageView.image = balloon.image
currentIndex += 1
}
func createBalloons() {
for var balloonCount = 0; balloonCount <= 99; ++balloonCount {
var balloon = Balloon();
balloon.number = balloonCount;
let randomNumber = Int(arc4random_uniform(UInt32(4)));
switch randomNumber {
case 1:
balloon.image = UIImage(named: "RedBalloon1.jpg")
case 2:
balloon.image = UIImage(named: "RedBalloon2.jpg")
case 3:
balloon.image = UIImage(named: "RedBalloon3.jpg")
default:
balloon.image = UIImage(named: "RedBalloon4.jpg")
}
self.balloons.append(balloon);
}
}
}
Balloon.swft:
import Foundation
import UIKit
struct Balloon {
var number = 0;
var image = UIImage(named: "");
}
答案 0 :(得分:4)
错误是说它不知道属性,backgroundimageView - 注意小写“i”。您的属性名称是带有大写“I”的backgroundImageView。在storyboard或xib中的某个位置,您正在使用此属性拼写错误。