[英]unrecognized selector sent to instance error in IOS App using Parse API
我正在尝试通过开发一个简单的应用程序来学习Ios应用程序开发,该应用程序从用户那里获取输入并将其使用Parse API保存在云中。
输入字段是firstName和lastName。
该API运作良好,我已经对其进行了测试(对要保存的值进行硬编码,而不是从屏幕上提取出来)。 但是,仅当我尝试从屏幕上获取输入并保存它时,才会出现该错误。
以下是代码:
viewcontroller.h
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *firstName;
@property (weak, nonatomic) IBOutlet UITextField *lastName;
- (IBAction)saveButton:(id)sender;
@end
视图控制器
#import "ViewController.h"
#import <Parse/Parse.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.
}
//*** Following works as I have hard coded the values to be stored and when I click directly on the save button. ***//
//*** But I want to get the content in firstName and lastName and save them using Parse API ***//
- (IBAction)saveButton:(UIButton *)sender {
PFObject *testObject = [PFObject objectWithClassName:@"NimbleIOS"];
testObject[@"FirstName"] = @"frst";// _firstName.text;
testObject[@"LastName"] = @"lst";// _lastName.text;
[testObject saveInBackground];
}
@end
error:
2014-11-19 22:38:45.229 Nimble[11714:541175] -[ViewController firstName:]: unrecognized selector sent to instance 0x7fe568e36160
2014-11-19 22:38:45.234 Nimble[11714:541175] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController firstName:]: unrecognized selector sent to instance 0x7fe568e36160'
*** First throw call stack:
(
0 CoreFoundation 0x000000010cd57f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c9f0bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010cd5f04d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010ccb727c ___forwarding___ + 988
4 CoreFoundation 0x000000010ccb6e18 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010d1458be -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010d24c410 -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010d8784cb -[UITextField _resignFirstResponder] + 256
8 UIKit 0x000000010d2bb47b -[UIResponder resignFirstResponder] + 114
9 UIKit 0x000000010d8782d4 -[UITextField resignFirstResponder] + 114
10 UIKit 0x000000010d2bb265 -[UIResponder becomeFirstResponder] + 284
11 UIKit 0x000000010d1b0e03 -[UIView(Hierarchy) becomeFirstResponder] + 99
12 UIKit 0x000000010d877ad7 -[UITextField becomeFirstResponder] + 51
13 UIKit 0x000000010d4ff9c1 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 177
14 UIKit 0x000000010d501a30 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2263
15 UIKit 0x000000010d4f72e6 _UIGestureRecognizerSendActions + 262
16 UIKit 0x000000010d4f5f89 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 532
17 UIKit 0x000000010d4faba6 ___UIGestureRecognizerUpdate_block_invoke662 + 51
18 UIKit 0x000000010d4faaa2 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 254
19 UIKit 0x000000010d4f0b1d _UIGestureRecognizerUpdate + 2796
20 UIKit 0x000000010d18aff6 -[UIWindow _sendGesturesForEvent:] + 1041
21 UIKit 0x000000010d18bc23 -[UIWindow sendEvent:] + 667
22 UIKit 0x000000010d1589b1 -[UIApplication sendEvent:] + 246
23 UIKit 0x000000010d165a7d _UIApplicationHandleEventFromQueueEvent + 17370
24 UIKit 0x000000010d141103 _UIApplicationHandleEventQueue + 1961
25 CoreFoundation 0x000000010cc8d551 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
26 CoreFoundation 0x000000010cc8341d __CFRunLoopDoSources0 + 269
27 CoreFoundation 0x000000010cc82a54 __CFRunLoopRun + 868
28 CoreFoundation 0x000000010cc82486 CFRunLoopRunSpecific + 470
29 GraphicsServices 0x00000001102429f0 GSEventRunModal + 161
30 UIKit 0x000000010d144420 UIApplicationMain + 1282
31 Nimble 0x000000010b545d43 main + 115
32 libdyld.dylib 0x000000010ea1c145 start + 1
33 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
有人可以帮助我知道我犯的错误吗? 我已经引用了两个文本字段以及从主板到视图控制器的保存按钮。 在文本字段中输入文本并将其移开(EditingDidEnd)并触摸屏幕上的其他位置后,出现错误。
firstName:方法在哪里? 我只看到一个名为saveButton的IBAction方法:即:saveButton是@selector()而不是firstName:我认为您需要在接口生成器中查看您的网点,看看是否仍然有一个旧的网点仍被连接为firstName:匹配字符串文字“ FirstName”
我没有使用PFObject类
我想你虽然在尝试做这样的事情
-(IBAction)saveButton:(UIButton *)sender{
if([sender.restorationIdentifier isEqualToString: @"res string from IB"]){
...take string from input source as a string and use it
maybe grab something from a textField or whatever
}else if...
}
您也可能要确保发件人实际上是一个UIButton,我看到您的公共api中列出了ID,而我刚读完底部,它说您要留下一个不是UIButton实例的textField!
我不小心在发送的事件中添加了“ EditingDidEnd”。 该代码期望在文本字段中编辑结束后立即发生。 该代码现在可以正常工作。 (在尝试使代码正常工作时,我已经写了我所理解的东西。如果我的理解是错误的,请更正我:))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.