简体   繁体   English

我得到__NSCFNumber isEqualToString:]错误

[英]I get a __NSCFNumber isEqualToString:] error

First of all, sorry for my english, it is not my native langage :) 首先,对不起我的英语,这不是我的本土语言:)

I'm getting this crash 我遇到了这个崩溃

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x68b9d00'". “由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [__ NSCFNumber isEqualToString:]:无法识别的选择器发送到实例0x68b9d00'”。

I saw a lot of similar errors and questions here but the cause were very different than mine. 我在这里看到了很多类似的错误和问题,但原因与我的有很大不同。

I have a NSObject that I try to pass trough a prepareForSegue called Event. 我有一个NSObject ,我尝试通过名为Event的prepareForSegue传递。 Event is composed by 3 NSString , here is my Event.h : 事件由3个NSString组成,这是我的Event.h:

@interface              Event : NSObject
{
    NSString*           idEvent;
    NSString*           lat;
    NSString*           lng;
}

@property NSString*     idEvent;
@property NSString*     lat;
@property NSString*     lng;

@end

When I get the Event object on the other side, I can output the content of the Event get(NSLog(@"%@", eventGet.lat); ) and it works fine. 当我在另一侧获得Event对象时,我可以输出Event get(NSLog(@"%@", eventGet.lat); )的内容get(NSLog(@"%@", eventGet.lat); )并且它可以正常工作。 But when I try to put the "eventGet.lat" into a UILabel , I get the error. 但是当我尝试将"eventGet.lat"放入UILabel ,我得到了错误。

Here is the code where the error occured : DetailEvent is the view where I get the Event. 以下是发生错误的代码:DetailEvent是我获取事件的视图。

DetailEvent.h : DetailEvent.h:

@interface  DetailEvent : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *latEvent;
@property (weak, nonatomic) IBOutlet UILabel *lngEvent;

@property (strong, nonatomic) Event* eventGet;

@end

And DetailEvent.m : 和DetailEvent.m:

@implementation DetailEvent

@synthesize latEvent            = _latEvent;
@synthesize lngEvent            = _lngEvent;

@synthesize eventToDisplay      = _eventToDisplay;

- (void)viewDidLoad
{
    [super viewDidLoad];

    // works fine
    NSLog(@"Event lat : %@", _eventToDisplay.lat);

    // here is the crash
    _latEvent.text = _eventToDisplay.lat;
}

This is confusing me and i would be very grateful! 这让我感到困惑,我将非常感激!

Thanks ! 谢谢 !

presumably, this is because the variable that is set is an NSNumber, not an NSString (as declared). 据推测,这是因为设置的变量是NSNumber,而不是NSString(如声明的那样)。 You could implement the setter for this variable and test the type is NSString when set to find the offenders. 您可以为此变量实现setter,并在设置为查找违规者时测试类型是NSString。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 - [__ NSCFNumber isEqualToString]错误 - -[__NSCFNumber isEqualToString] error 为什么我会比较NSString的错误? ( - [__ NSCFNumber isEqualToString:]:发送到实例的无法识别的选择器) - Why do i get an error comparing NSString's? (-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance) 错误:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [NSCFNumber isEqualToString:]: - Error:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber isEqualToString:]: [NSCFNumber isEqualToString:]:发送到实例的无法识别的选择器 - [NSCFNumber isEqualToString:]: unrecognized selector sent to instance 如何获得NSCFNumber的绝对值? - How do I get absolute value of NSCFNumber? NSCFNumber isEqualToString:viewDidLoad和viewWillApear之间的IOS11崩溃 - NSCFNumber isEqualToString: crash IOS11 between viewDidLoad and viewWillApear 在iOS UIAlertView中设置NSString文本崩溃,获取错误__NSCFNumber _isNaturallyRTL - setting NSString text in iOS UIAlertView crashing, get error __NSCFNumber _isNaturallyRTL NCFictionary的NSCFNumber escapedString错误 - NSCFNumber escapedString Error with a NSDictionary “isEqualToString”Cocoa错误 - “isEqualToString” Cocoa error 为什么在此可可代码中出现isEqualToString错误? - Why am I getting an isEqualToString error in this Cocoa code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM