我正在构建一个包含很多视图的应用。在某一点上,按下按钮后,视图会从一个视图更改回初始视图控制器。初始View Controller只有在创建新类时添加的默认代码,它唯一用于保存用于切换到其他视图的按钮。带按钮的视图有一个textField,一个“退出”按钮和几个标签。如果我按下退出按钮而不用触摸textField,一切顺利,我将被带回原始视图控制器,我可以继续。但是,如果我决定在textField上编辑(甚至只是打开键盘),然后按退出按钮,应用程序崩溃,出现sigabrt错误。这是我得到的错误代码。
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是用于带有textField的View Controller的类的名称,answerBox是textField的名称。任何帮助将不胜感激。
初始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.
}
@end
那里什么也没发生,这是默认内容。
初始viewController的.h文件:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface ViewController : UIViewController
{
}
@end
再次,默认内容。
使用退出按钮的.m文件
查看控制器#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
带有一些额外导入的默认内容。
使用退出按钮的.h文件
查看控制器#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
只是一些IBOutlets和NSIntegers。
答案 0 :(得分:1)
检查你的笔尖/故事板,你没有任何迷路连接。看起来您的UITextField上可能有一个操作。