I am building an app that has many views. At one point, upon a press of a button, the view changes from one view back to the initial View Controller. The initial View Controller has nothing but the default code that gets added when creating a new class, the only thing it's used for is to hold buttons that are used to switch to other views. The view with the button has a textField, a "Quit" button and a couple labels. If I press the Quit button without touching the textField, all goes well, and I am taken back to the original view controller, where I am able to continue. However, if I decide to edit (or even just open the keyboard) on the textField, and then press the quit button, the app crashes, a sigabrt error. This is the error code I get.
2016-01-28 17:16:59.666 AutoTutor[64646:2461958] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ATPractice answerBox:]: unrecognized selector sent to instance 0x7fb58855d1e0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000104579e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000103ff2deb objc_exception_throw + 48
2 CoreFoundation 0x000000010458248d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001044cf90a ___forwarding___ + 970
4 CoreFoundation 0x00000001044cf4b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000104928194 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x0000000104a976fc -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000104a979c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x00000001052ff506 -[UITextField _resignFirstResponder] + 298
9 UIKit 0x0000000104b346ea -[UIResponder _finishResignFirstResponder] + 292
10 UIKit 0x00000001052ff330 -[UITextField _finishResignFirstResponder] + 49
11 UIKit 0x0000000104b34799 -[UIResponder resignFirstResponder] + 140
12 UIKit 0x00000001052ff1fd -[UITextField resignFirstResponder] + 136
13 UIKit 0x00000001049c9605 -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 161
14 UIKit 0x00000001049c9b32 __UIViewWillBeRemovedFromSuperview + 71
15 UIKit 0x00000001049c9950 -[UIView(Hierarchy) removeFromSuperview] + 99
16 UIKit 0x0000000104a93493 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke596 + 739
17 UIKit 0x0000000104a8d756 -[UIPresentationController transitionDidFinish:] + 111
18 UIKit 0x0000000104c62e0b -[_UICurrentContextPresentationController transitionDidFinish:] + 42
19 UIKit 0x0000000104a91159 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
20 UIKit 0x000000010532cd20 -[_UIViewControllerTransitionContext completeTransition:] + 101
21 UIKit 0x0000000104a8a90f -[UITransitionView notifyDidCompleteTransition:] + 252
22 UIKit 0x0000000104a8a620 -[UITransitionView _didCompleteTransition:] + 1344
23 UIKit 0x0000000104a8cd8c -[UITransitionView _transitionDidStop:finished:] + 104
24 UIKit 0x00000001049b02af -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 241
25 UIKit 0x00000001049b065e -[UIViewAnimationState animationDidStop:finished:] + 80
26 QuartzCore 0x0000000107370fa0 _ZN2CA5Layer23run_animation_callbacksEPv + 308
27 libdispatch.dylib 0x0000000107f8e49b _dispatch_client_callout + 8
28 libdispatch.dylib 0x0000000107f762af _dispatch_main_queue_callback_4CF + 1738
29 CoreFoundation 0x00000001044d9d09 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
30 CoreFoundation 0x000000010449b2c9 __CFRunLoopRun + 2073
31 CoreFoundation 0x000000010449a828 CFRunLoopRunSpecific + 488
32 GraphicsServices 0x0000000107a2aad2 GSEventRunModal + 161
33 UIKit 0x0000000104926610 UIApplicationMain + 171
34 AutoTutor 0x000000010379a8ef main + 111
35 libdyld.dylib 0x0000000107fc292d start + 1
36 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
ATPractice is the name of the class used for the View Controller with the textField, and answerBox is the name of the textField. Any help would be greatly appreciated.
The initial viewController's .m file:
#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.
}
@end
Nothing going on in there, it's the default contents.
The initial viewController's .h file:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface ViewController : UIViewController
{
}
@end
Again, default contents.
View Controller with the quit button's .m file
#import "ATPractice.h"
#import "DDMathParser.h"
#import <AVFoundation/AVFoundation.h>
@interface ATPractice ()
@end
@implementation ATPractice
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
Default contents with some extra imports.
View Controller with the quit button's .h file
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
@interface ATPractice : UIViewController <UITextFieldDelegate>
{
IBOutlet UILabel *instructionsLabel;
IBOutlet UILabel *questionLabel;
IBOutlet UILabel *percentageLabel;
IBOutlet UILabel *levelLabel;
IBOutlet UIImageView *imageView;
IBOutlet UITextField *answerBox;
IBOutlet UIScrollView *zoomView;
NSInteger questionInt;
NSInteger levelInt;
}
@end
Just some IBOutlets and NSIntegers.
Check your nibs/storyboards that you've not got any stray connections. It looks like there might be one on your UITextField for one of its actions.