- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我仅在 IOS 11 上发生崩溃:[__NSCFNumber isEqualToString:]: 无法识别的选择器发送到实例
Debug step by step表示崩溃发生在viewDidLoad结束后,进入viewWillApear之前
如何调试?
我尝试使用异常断点,但没有更多信息。崩溃很明显,但我没有任何代码,在崩溃之前或之后我不使用“isEqualToString”或“objectAtIndex”...
ViewDidLoad代码:
self.buttonCancel = [[UIBarButtonItem alloc] initWithTitle:@"ANNULER" style:UIBarButtonItemStylePlain target:self action:@selector(actionCancel)];
[self.buttonCancel setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [EATColor colorBlack], NSForegroundColorAttributeName,[EATFont ElleNovaCExtraBold:12],NSFontAttributeName,NSKernAttributeName, @(0.66), nil] forState:UIControlStateNormal];
[super viewDidLoad];
// Do any additional setup after loading the view.
[self buildCollectionViewListing];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.backgroundColor = [UIColor clearColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"ANNULER"];
[self.collectionView registerNib:[UINib nibWithNibName:@"EATSearchRecetteCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"idSearchRecette"];
[self.collectionView registerNib:[UINib nibWithNibName:@"EATSearchArticleCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"idSearchNews"];
[self.collectionView registerNib:[UINib nibWithNibName:@"EATSearchGalleryCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"idSearchGallery"];
[self.collectionView registerNib:[UINib nibWithNibName:@"EATSearchVideoCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"idSearchVideo"];
[self.collectionView registerNib:[UINib nibWithNibName:@"EATSearchHeaderCollectionViewCell" bundle:[NSBundle mainBundle]] forSupplementaryViewOfKind: UICollectionElementKindSectionHeader withReuseIdentifier:EATSearchHeaderCollectionViewIdentifier];
if (self.searchedText) {
if (self.searchBar) {
self.searchBar.text = self.searchedText;
}else {
self.title = [self.searchedText uppercaseString];
}
[self loadData];
}
最佳答案
那是罪魁祸首:
[self.buttonCancel setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [EATColor colorBlack], NSForegroundColorAttributeName,[EATFont ElleNovaCExtraBold:12],NSFontAttributeName,NSKernAttributeName, @(0.66), nil] forState:UIControlStateNormal];
发生了什么事?
[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance
这意味着在某个时候有一个 NSNumber
对象调用一个方法 isEqualToString:
。它不知道它(它是一个 NSString
方法),然后它崩溃了。
没有说的是您不必调用自己 isEqualToString:
,它可能是 Apple SDK 代码中的隐藏调用,这就是正在发生的事情。
NSAttributedString
的属性字典必须有 NSString
键,值必须是键文档中对应的类(有时是 NSNumber
,有时是 UIFont
,UIColor
) 等
在你的例子中,你倒置了最后一个键和对象,dictionaryWithObjectsAndKeys:
等待对象,然后是键。但在最后一个填充值中,你将它们反转 (NSKernAttributeName, @(0.66)
)。它仍然是一个有效的字典,但不遵守属性规则。
所以在某些时候 Apple 代码会检查每个键,比较它们(调用 isEqualToString:
以了解需要应用哪些效果。但它会将 @(0.66) 与 NSSomeAttributeName
([@(0.66)isEqualToString:NSSomeAttributeName]
) 而不是首先检查 @(0.66)
的类。
修复:
[self.buttonCancel setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [EATColor colorBlack], NSForegroundColorAttributeName,[EATFont ElleNovaCExtraBold:12],NSFontAttributeName,@(0.66), NSKernAttributeName, nil] forState:UIControlStateNormal];
写起来更简单(而且更容易一眼看出什么是键,什么是值):
[self.buttonCancel setTitleTextAttributes:@{NSForegroundColorAttributeName: [EATColor colorBlack],
NSFontAttributeName: [EATFont ElleNovaCExtraBold:12],
NSKernAttributeName: @(0.66)}
forState:UIControlStateNormal];
关于ios - NSCFNumber isEqualToString : crash IOS11 between viewDidLoad and viewWillApear,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46709085/
好的,我以前做过这个,很简单,但出于某种原因我不明白为什么下面的两个字符串彼此不相等!有任何想法吗?我确信这将是我没有看到的非常容易的事情: NSString *texture1name = [NSS
我正在尝试将字符串设置为“如果 [object objectForKey@"display_name"] 为 NULL,则不显示名称”。它在日志中崩溃了 2011-06-16 10:58:36.251
我有一个案例,我想检查我拥有的一个可选值是否等于一个字符串。首先我必须打开它来检查它是否存在,然后我想检查它是否等于另一个字符串。但是,这给了我一个问题,我必须两次编写相同的代码。我给你举个例子:
这个问题已经有答案了: What is the diffrence between isEqualToString and operator == in Objective C? (2 个回答) 已关
所以这是迄今为止我见过的最奇怪的崩溃。这是崩溃:代码: 2011-08-21 21:04:39.321 App[548:707] -[__NSDate isEqualToString:]: unrec
我正在制作一个应用程序,它创建一个新日历,然后使用该日历添加事件等。我可以很好地创建日历,但我试图运行检查以查看日历是否存在,因此,不要每次都创建第二个具有相同名称的日历。换句话说,只需创建一次新日历
我正在尝试检查 .json 文件中的值是“0”还是“1”。 我的 .json 文件: { "timetable": [ { "50mhour": "1",
我正在尝试使用 parse.com 上的字符串来设置 UILabel 中的文本。在 Parse 上,我有一个名为“isItemOnSpecial”的字符串列,如果该项目是特殊的,我会将其设置为是。如果
所以我有一个检查 URL 的方法,并且只允许在 Web View 中加载特定的 URL。 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWit
我正在制作一个应用程序,并尝试使用 isEqualToString 与我知道相同的字符串进行比较。但是,此代码不起作用 - (void)uui { array2 = [NSMutableArr
下面的示例程序输出相同,但程序无法正常运行。 NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager]
在我开始之前这里有一些背景知识,基本上我们正在寻找将 UDP 响应与存储在我们应用程序的 Parse 数据库中的字符串进行比较。这个问题是我似乎无法让 isEqualToString 函数将字符串视为
类定义如下: @interface KNBookmark : NSObject @property (nonatomic, strong) NSString *bookmarkId ; @proper
我在我的应用程序中使用此代码。刚刚对比韩文发现不对 for (NSString *lang in array){ NSString *currentLang = [[M
我的控制台出现错误: 2009-05-30 20:17:05.801 ChuckFacts[1029:20b] *** -[Joke isEqualToString:]: unrecognized s
我有多个字符串组合,我希望 isEqualtoString 自动找到它们。现在,我手动搜索了所有组合。 if([aString isEqualToString:@"xyz"] || [aString
我正在研究这个: NSString *str1 = @"This is string A"; NSString *str2 = @"This is string B"; NSComparisonRes
我不断遇到(罕见)NSStrings 不返回相等的情况,尽管它们在控制台中打印时看起来完全相同。例如: [string1 isEqualToString:string2] > comparing 'a
即使您在运行程序时键入“stop”,“Stopping”语句也不会被打印。 initWithUTF8String: 方法是否引入了额外的格式? int main (int argc, const ch
我使用创建一个 NSString, NSString *myString = [[NSString alloc] initWithBytes:someBuffer length:sizeof(some
我是一名优秀的程序员,十分优秀!