This question already has answers here:
setValue:forUndefinedKey: this class is not key value coding-compliant for the key [duplicate]
(20 answers)
Closed 8 years ago.
I'm receiving an error while running my xcode project. My app always work, so I can't really see why this isn't working any more. Does anyone have an idea? I've found that it's caused due to an invalid method I'm calling. I can't seem to figure out where this mistake is located.. Anyone?
The error I get:
2014-02-25 11:52:06.784 Chemie Xpert - PSE[1381:70b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x8d49be0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
*** First throw call stack:
(
0 CoreFoundation 0x023625e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44
2 CoreFoundation 0x023f26a1 -[NSException raise] + 17
3 Foundation 0x00f709ee -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x00edccfb _NSSetUsingKeyValueSetter + 88
5 Foundation 0x00edc253 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 Foundation 0x00f3e70a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
7 UIKit 0x002bfa15 -[UIRuntimeOutletConnection connect] + 106
8 libobjc.A.dylib 0x014ce7d2 -[NSObject performSelector:] + 62
9 CoreFoundation 0x0235db6a -[NSArray makeObjectsPerformSelector:] + 314
10 UIKit 0x002be56e -[UINib instantiateWithOwner:options:] + 1417
11 UIKit 0x002c02fb -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 165
12 UIKit 0x0001d3bb -[UIApplication _loadMainNibFileNamed:bundle:] + 58
13 UIKit 0x0001d6e9 -[UIApplication _loadMainInterfaceFile] + 245
14 UIKit 0x0001c28f -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 543
15 UIKit 0x0003087c -[UIApplication handleEvent:withNewEvent:] + 3447
16 UIKit 0x00030de9 -[UIApplication sendEvent:] + 85
17 UIKit 0x0001e025 _UIApplicationHandleEvent + 736
18 GraphicsServices 0x022c02f6 _PurpleEventCallback + 776
19 GraphicsServices 0x022bfe01 PurpleEventCallback + 46
20 CoreFoundation 0x022ddd65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
21 CoreFoundation 0x022dda9b __CFRunLoopDoSource1 + 523
22 CoreFoundation 0x0230877c __CFRunLoopRun + 2156
23 CoreFoundation 0x02307ac3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x023078db CFRunLoopRunInMode + 123
25 UIKit 0x0001badd -[UIApplication _run] + 840
26 UIKit 0x0001dd3b UIApplicationMain + 1225
27 Chemie Xpert - PSE 0x0000247d main + 141
28 libdyld.dylib 0x0598d70d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
My code:
main.m:
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webview;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html" inDirectory:#"localHTML"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
webview.scalesPageToFit = YES;
webview.scrollView.bounces = NO;
webview.scrollView.minimumZoomScale = 1;
webview.scrollView.bouncesZoom = FALSE;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
#end
Maybe you deleted the UIView object from the NIB and replaced with the UIWebView.
This is fine, but you should link the webView to the "view" property of the viewController in the xib file.
Is the webview set as an IBOutlet? That could be the cause.
Related
I press on CONTROL and drag the UIImageVIew and UILabel which is in AppView.xib to my code file named "AppVIew.h". Before I connect the two UI widgets it ran ok ,I want to know the reasons leading to the crash.Very thanks for your answers.
#property
The code as following:
#import <UIKit/UIKit.h>
#interface AppView : UIView
#property (weak, nonatomic) IBOutlet UIImageView *icon;
#property (weak, nonatomic) IBOutlet UILabel *name;
+ (id)AppViewWithIcon:(NSString *)icon Name:(NSString *)name;
#end
#import "AppView.h"
#implementation AppView
+ (id)AppViewWithIcon:(NSString *)icon Name:(NSString *)name{
AppView *view = [[NSBundle mainBundle] loadNibNamed:#"AppView" owner:nil options:nil][0];
NSLog(#"%#",view);
return view;
}
the errors as following:
1.Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP,subcode=0X0)
2.2016-03-27 18:53:36.804 05-九宫格[4302:283744] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x7fca52c1a1c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key icon.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101630d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001010a4deb objc_exception_throw + 48
2 CoreFoundation 0x00000001016309c9 -[NSException raise] + 9
3 Foundation 0x0000000100c6f19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000101db07fb -[UIRuntimeOutletConnection connect] + 109
5 CoreFoundation 0x000000010156a890 -[NSArray makeObjectsPerformSelector:] + 224
6 UIKit 0x0000000101daf1de -[UINib instantiateWithOwner:options:] + 1864
7 UIKit 0x0000000101db1415 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 223
8 05-九宫格 0x0000000100ba1490 +[AppView AppViewWithIcon:Name:] + 160
9 05-九宫格 0x0000000100ba0cae -[ViewController viewDidLoad] + 206
10 UIKit 0x0000000101b81984 -[UIViewController loadViewIfRequired] + 1198
11 UIKit 0x0000000101b81cd3 -[UIViewController view] + 27
12 UIKit 0x0000000101a57fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000101a5869d -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000101a6a180 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x00000001019deed9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x00000001019e5568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
17 UIKit 0x00000001019e2714 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x000000010444f8c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x000000010444f741 -[FBSSerialQueue _performNext] + 178
20 FrontBoardServices 0x000000010444faca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x0000000101556301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010154c22c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x000000010154b6e3 __CFRunLoopRun + 867
24 CoreFoundation 0x000000010154b0f8 CFRunLoopRunSpecific + 488
25 UIKit 0x00000001019e1f21 -[UIApplication _run] + 402
26 UIKit 0x00000001019e6f09 UIApplicationMain + 171
27 05-九宫格 0x0000000100ba195f main + 111
28 libdyld.dylib 0x0000000103e0a92d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Check if their are any previous outlets that have been deleted from within the storyboard, by either checking the view controller inspector and referencing outlets for any outlets that may contradict the ones you have made as well as the UIView/UILabel.
I'am a super a super rookie in IOS. I am doing a login feature. When the login in button is pressed, the APP shall check the text from storage. Then it should change to the second VC if check status return true. I currently have a ViewController to ViewController segue with identifier. I tried the perform segue with identifier but it doesn't work.(Doesn't change scene and shows no alert.)
Here is the login Page.
#import
#interface LoginPage : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *usernameField;
#property (strong, nonatomic) IBOutlet UITextField *passwordField;
- (IBAction)LoginTapped:(id)sender;
- (IBAction)SignupTapped:(id)sender;
#end
the login.m
#import "LoginPage.h"
#import "Home.h"
#implementation LoginPage
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)LoginTapped:(id)sender {
NSMutableDictionary *infodictionary =[[NSMutableDictionary alloc] init];
[infodictionary setObject:#"1" forKey:#"rose"];
[infodictionary setObject:#"2" forKey:#"cathy"];
[infodictionary setObject:#"3" forKey:#"corey"];
if ([_passwordField.text isEqualToString:[infodictionary objectForKey: _usernameField.text]]){
// Home *home = [[Home alloc] init];
[self performSegueWithIdentifier:#"ToHome" sender:self];
}
}
- (IBAction)SignupTapped:(id)sender {
NSString *_NAME = [NSString alloc];
NSString *_PASS = [NSString alloc];
_NAME= _usernameField.text;
_PASS = _passwordField.text;
}
#end
the stimulator gives me terminating with uncaught exception of type NSException
2016-02-07 05:39:49.437 project_feature_login[8249:941926] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7fb5f9c98300> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key passwordField.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102b18f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102592deb objc_exception_throw + 48
2 CoreFoundation 0x0000000102b18b89 -[NSException raise] + 9
3 Foundation 0x000000010215fa6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x000000010305004c -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010327da71 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x0000000102a59a80 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010327c454 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000103056c16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000103057542 -[UIViewController loadView] + 178
10 UIKit 0x00000001030578a0 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000103058013 -[UIViewController view] + 27
12 UIKit 0x0000000102f3151c -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000102f31c05 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000102f434a5 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000102ebd396 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000102ec39c3 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1750
17 UIKit 0x0000000102ec0ba3 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000105870784 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000105870af2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x0000000102a45011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x0000000102a3af3c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x0000000102a3a3f3 __CFRunLoopRun + 867
23 CoreFoundation 0x0000000102a39e08 CFRunLoopRunSpecific + 488
24 UIKit 0x0000000102ec04f5 -[UIApplication _run] + 402
25 UIKit 0x0000000102ec530d UIApplicationMain + 171
26 project_feature_login 0x0000000102094a6f main + 111
27 libdyld.dylib 0x000000010523c92d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
Seeking for Help!!!!
Try using self.passwordField.text instead of _passwordField.text while verifying your if condition. Also check the IBOutlet connection of passwordField in Interface Builder. Class set for that UIViewController in interface must be LoginPage
My app was working fine this morning. I updated to Xcode 5.1 and when I run my app, it crashes when I hit play. My app has a modal button that leads to another view controller. The first view controller is the main screen. I start the app, press the play button, then it does nothing for about a second (instead of taking me to the second view controller, which is the game itself), and then Xcode takes me to the main.m. This is what my main.m looks like (have not modified it). So, when Xcode takes me here, the line that starts with return UIApplicationMain is highlighted in green and on the far right it says thread 1: signal SIGABRT
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Does anyone have a suggestion about what is going on?
------updated
I am not sure if this helps (because I'm still a beginner, but i think this is it). it says:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter' *** First throw call stack:
(
0 CoreFoundation 0x01f0c1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0180a8e5 objc_exception_throw + 44
2 CoreFoundation 0x01f0bfbb +[NSException raise:format:] + 139
3 Foundation 0x0142692b -[NSURL(NSURL) initFileURLWithPath:] + 123
4 Foundation 0x014267fd +[NSURL(NSURL) fileURLWithPath:] + 67
5 Bad Jetpack Complete 0x00004f92 -[Game viewDidLoad] + 1170
6 UIKit 0x005e933d -[UIViewController loadViewIfRequired] + 696
7 UIKit 0x005e95d9 -[UIViewController view] + 35
8 UIKit 0x005f8f89 -[UIViewController shouldAutorotate] + 36
9 UIKit 0x005f92d1 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 297
10 UIKit 0x008973d5 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2330
11 UIKit 0x005f55d5 -[UIViewController presentViewController:withTransition:completion:] + 6538
12 UIKit 0x005f5aef -[UIViewController presentViewController:animated:completion:] + 130
13 UIKit 0x005f5b2f -[UIViewController presentModalViewController:animated:] + 56
14 UIKit 0x00a3fe00 -[UIStoryboardModalSegue perform] + 271
15 UIKit 0x00a2ef0c -[UIStoryboardSegueTemplate _perform:] + 174
16 UIKit 0x00a2ef87 -[UIStoryboardSegueTemplate perform:] + 115
17 libobjc.A.dylib 0x0181c880 -[NSObject performSelector:withObject:withObject:] + 77
18 UIKit 0x004cc3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
19 UIKit 0x004cc345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
20 UIKit 0x005cdbd1 -[UIControl sendAction:to:forEvent:] + 66
21 UIKit 0x005cdfc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
22 UIKit 0x005cd243 -[UIControl touchesEnded:withEvent:] + 641
23 UIKit 0x0050bddd -[UIWindow _sendTouchesForEvent:] + 852
24 UIKit 0x0050c9d1 -[UIWindow sendEvent:] + 1117
25 UIKit 0x004de5f2 -[UIApplication sendEvent:] + 242
26 UIKit 0x004c8353 _UIApplicationHandleEventQueue + 11455
27 CoreFoundation 0x01e9577f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
28 CoreFoundation 0x01e9510b __CFRunLoopDoSources0 + 235
29 CoreFoundation 0x01eb21ae __CFRunLoopRun + 910
30 CoreFoundation 0x01eb19d3 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x01eb17eb CFRunLoopRunInMode + 123
32 GraphicsServices 0x030885ee GSEventRunModal + 192
33 GraphicsServices 0x0308842b GSEventRun + 104
34 UIKit 0x004caf9b UIApplicationMain + 1225
35 Bad Jetpack Complete 0x00002e7d main + 141
36 libdyld.dylib 0x03c7f701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
- (void)viewDidLoad
{
CactusTop.hidden = YES;
CactusBottom.hidden = YES;
ScoreLabel.hidden = YES;
GameOverScreen.hidden = YES;
RestartButton.hidden = YES;
LeaderBoardButton.hidden = YES;
ScoreLabel2.hidden = YES;
HighscoreLabel.hidden = YES;
RestartButton.hidden = YES;
HighScoreNumber = [[NSUserDefaults standardUserDefaults] integerForKey:#"HighScoreSaved"];
NSURL *ClickURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Click"ofType:#"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)ClickURL, & ClickSound);
NSURL *ExplosionURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Explosion" ofType:#"mp3"]];
ExplosionSound = [[AVAudioPlayer alloc] initWithContentsOfURL:ExplosionURL error:nil];
[ExplosionSound setNumberOfLoops:0];
[ExplosionSound prepareToPlay];
NSURL *JetpackURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Jetpack 1_2sec_01c" ofType:#"mp3"]];
JetpackSound = [[AVAudioPlayer alloc] initWithContentsOfURL:JetpackURL error:nil];
[JetpackSound setNumberOfLoops:0];
[JetpackSound prepareToPlay];
NSURL *PointURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Point" ofType:#"mp3"]];
PointSound = [[AVAudioPlayer alloc] initWithContentsOfURL:PointURL error:nil];
[PointSound setNumberOfLoops:0];
[PointSound prepareToPlay];
this is the updated question with the view did load
OK, somewhere in your app you are trying to load a file from a URL but the URL is nil.
Can you show the code where you are doing this. It will help answer you question.
Actually, it's in the file Game.m in the method - (void)viewDidLoad;.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is what I get when I press the done button on the keyboard of a UITextField: (code to follow)
2013-10-14 23:22:55.170 What to where?[21627:a0b] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x0008e5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0178e8b6 objc_exception_throw + 44
2 CoreFoundation 0x00042a32 -[__NSArrayI objectAtIndex:] + 210
3 What to where? 0x00002670 -[ViewController getWeatherForecast] + 352
4 What to where? 0x00002430 -[ViewController textFieldDidEndEditing:] + 288
5 libobjc.A.dylib 0x017a081f -[NSObject performSelector:withObject:] + 70
6 UIKit 0x00502c8c -[UIApplication sendAction:to:from:forEvent:] + 108
7 UIKit 0x00502c18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8 UIKit 0x005fa6d9 -[UIControl sendAction:to:forEvent:] + 66
9 UIKit 0x005faa9c -[UIControl _sendActionsForEvents:withEvent:] + 577
10 UIKit 0x00bddaf3 -[UITextField _resignFirstResponder] + 300
11 UIKit 0x0065a71e -[UIResponder _finishResignFirstResponder] + 181
12 UIKit 0x0065a82f -[UIResponder resignFirstResponder] + 265
13 UIKit 0x00bdd894 -[UITextField resignFirstResponder] + 118
14 What to where? 0x000024d9 -[ViewController textFieldShouldReturn:] + 137
15 UIKit 0x00be68bf -[UITextField keyboardInput:shouldInsertText:isMarkedText:] + 357
16 UIKit 0x006d5a43 -[UIKeyboardImpl callShouldInsertText:] + 271
17 UIKit 0x006dfd20 -[UIKeyboardImpl addWordTerminator:afterSpace:elapsedTime:executionContext:] + 63
18 UIKit 0x006df81a -[UIKeyboardImpl completeAcceptCandidateBeforeAddingInput:executionContext:] + 1668
19 UIKit 0x006df0f6 __60-[UIKeyboardImpl addInputString:withFlags:executionContext:]_block_invoke + 53
20 UIKit 0x00c0dc6e -[UIKeyboardTaskExecutionContext returnExecutionToParent] + 254
21 UIKit 0x006e299b -[UIKeyboardImpl acceptCurrentCandidateIfSelectedWithExecutionContext:] + 250
22 UIKit 0x006df0b9 -[UIKeyboardImpl addInputString:withFlags:executionContext:] + 451
23 UIKit 0x006ddf7f -[UIKeyboardImpl handleStringInput:withFlags:executionContext:] + 248
24 UIKit 0x006ec16f -[UIKeyboardImpl handleKeyWithString:forKeyEvent:executionContext:] + 633
25 UIKit 0x006ebcb6 -[UIKeyboardImpl handleKeyEvent:executionContext:] + 1808
26 UIKit 0x006eb50f __33-[UIKeyboardImpl handleKeyEvent:]_block_invoke + 51
27 UIKit 0x006eb31c -[UIKeyboardImpl _handleKeyEvent:executionContext:] + 243
28 UIKit 0x008642e9 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 4078
29 UIKit 0x00862def -[UIKeyboardLayoutStar touchUp:executionContext:] + 1545
30 UIKit 0x006f9398 __28-[UIKeyboardLayout touchUp:]_block_invoke + 269
31 UIKit 0x00c0e1b8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
32 UIKit 0x00c0e85f -[UIKeyboardTaskQueue addTask:] + 144
33 UIKit 0x006f9283 -[UIKeyboardLayout touchUp:] + 263
34 UIKit 0x006f9db9 -[UIKeyboardLayout touchesEnded:withEvent:] + 362
35 UIKit 0x005400cd -[UIWindow _sendTouchesForEvent:] + 852
36 UIKit 0x00540d34 -[UIWindow sendEvent:] + 1232
37 UIKit 0x00514a36 -[UIApplication sendEvent:] + 242
38 UIKit 0x004fed9f _UIApplicationHandleEventQueue + 11421
39 CoreFoundation 0x000178af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
40 CoreFoundation 0x0001723b __CFRunLoopDoSources0 + 235
41 CoreFoundation 0x0003430e __CFRunLoopRun + 910
42 CoreFoundation 0x00033b33 CFRunLoopRunSpecific + 467
43 CoreFoundation 0x0003394b CFRunLoopRunInMode + 123
44 GraphicsServices 0x036859d7 GSEventRunModal + 192
45 GraphicsServices 0x036857fe GSEventRun + 104
46 UIKit 0x0050194b UIApplicationMain + 1225
47 What to where? 0x00002d3d main + 141
48 libdyld.dylib 0x01fbf725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The code in the .h :
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface ViewController : UIViewController <UITextFieldDelegate> {
NSString *location;
NSString *time;
}
#property (strong, nonatomic) IBOutlet UITextField *destinationTF;
#property (strong, nonatomic) IBOutlet UITextField *timeTF;
- (IBAction)textFieldDidEndEditing:(id)sender;
#end
And the .m:
#synthesize destinationTF, timeTF;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)textFieldDidEndEditing:(id)sender {
if (sender == destinationTF ) {
location = destinationTF.text;
} else if (sender == timeTF) {
time = timeTF.text;
}
[self getWeatherForecast];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[destinationTF resignFirstResponder];
[timeTF resignFirstResponder];
return YES;
}
0x00042a32 -[__NSArrayI objectAtIndex:] + 210
I don't have the source code to your getWeatherForcast method, but I would guess that that array is empty. Before you execute any code on the array try:
if ([someArray lastObject]) {
..Do something
} else {
do something if the test fails
}
This is safe and will not crash because the array is out of bounds. (It just returns nil)
I think iOS 7 added firstObject as well.
The crash is due to an index out of bounds error and it is occurring in your getWeatherForecast method. You may be attempting to get an object out of an empty array...
Another problem that is causing my build to succeed, then terminate. As follows:
Error:
2013-09-30 20:21:23.708 The Solver[2566:a0b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x89bfd40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key welcomeBeta.'
*** First throw call stack:
(
0 CoreFoundation 0x023615e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bf8b6 objc_exception_throw + 44
2 CoreFoundation 0x023f16a1 -[NSException raise] + 17
3 Foundation 0x00f73c2e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x00edff3b _NSSetUsingKeyValueSetter + 88
5 Foundation 0x00edf493 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
6 UIKit 0x0008f97b -[UIView(CALayerDelegate) setValue:forKey:] + 168
7 Foundation 0x00f4194a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
8 UIKit 0x002c6cd5 -[UIRuntimeOutletConnection connect] + 106
9 libobjc.A.dylib 0x014d17d2 -[NSObject performSelector:] + 62
10 CoreFoundation 0x0235cb6a -[NSArray makeObjectsPerformSelector:] + 314
11 UIKit 0x002c582e -[UINib instantiateWithOwner:options:] + 1417
12 UIKit 0x00137c95 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
13 UIKit 0x0013843d -[UIViewController loadView] + 302
14 UIKit 0x0013873e -[UIViewController loadViewIfRequired] + 78
15 UIKit 0x00138c44 -[UIViewController view] + 35
16 UIKit 0x000615ad -[UIWindow addRootViewControllerViewIfPossible] + 66
17 UIKit 0x00061947 -[UIWindow _setHidden:forced:] + 312
18 UIKit 0x00061bdd -[UIWindow _orderFrontWithoutMakingKey] + 49
19 UIKit 0x0006c44a -[UIWindow makeKeyAndVisible] + 65
20 UIKit 0x0001f8e0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
21 UIKit 0x00023fb8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
22 UIKit 0x0003842c -[UIApplication handleEvent:withNewEvent:] + 3447
23 UIKit 0x00038999 -[UIApplication sendEvent:] + 85
24 UIKit 0x00025c35 _UIApplicationHandleEvent + 736
25 GraphicsServices 0x022bf2eb _PurpleEventCallback + 776
26 GraphicsServices 0x022bedf6 PurpleEventCallback + 46
27 CoreFoundation 0x022dcdd5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
28 CoreFoundation 0x022dcb0b __CFRunLoopDoSource1 + 523
29 CoreFoundation 0x023077ec __CFRunLoopRun + 2156
30 CoreFoundation 0x02306b33 CFRunLoopRunSpecific + 467
31 CoreFoundation 0x0230694b CFRunLoopRunInMode + 123
32 UIKit 0x000236ed -[UIApplication _run] + 840
33 UIKit 0x0002594b UIApplicationMain + 1225
34 The Solver 0x000033dd main + 141
35 libdyld.dylib 0x059a5725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Code for UIControllerView with welcomeBeta (Button)
WelcomeUI.h:
#import <UIKit/UIKit.h>
#interface WelcomeUI : UIViewController
#property (weak, nonatomic) IBOutlet UIButton *welcomeStart;
#property (weak, nonatomic) IBOutlet UIButton *welcomeBeta;
#end
WelcomeUI.m:
#import "WelcomeUI.h"
#interface WelcomeUI ()
#end
#implementation WelcomeUI
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Please let me know where I'm going wrong. Also explain in detail as I'm new to objective-c and Xcode.