[英]iOS app crashes when changing views
我正在构建一个具有很多视图的应用程序。 有时,只要按下按钮,视图就会从一个视图变回初始的View Controller。 最初的View Controller除了创建新类时添加的默认代码外什么都没有,它唯一要做的就是按住用于切换到其他视图的按钮。 带按钮的视图具有textField,“ Quit”按钮和几个标签。 如果我在不触摸textField的情况下按了Quit按钮,一切都会顺利进行,然后将我带回到原始视图控制器,在这里我可以继续。 但是,如果我决定在textField上进行编辑(甚至只是打开键盘),然后按退出按钮,则应用程序将崩溃,这是一个错误。 这是我得到的错误代码。
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文件的View Controller
#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文件的View Controller
#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。
检查笔尖/故事板是否没有任何杂散连接。 看起来您的UITextField上可能有一项动作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.