我正在我的 iOS 应用程序中设置以下功能:
- (IBAction)nextButton:(id)sender
{
if (self.itemSearch.text.length > 0) {
[PFCloud callFunctionInBackground:@"eBayCategorySearch"
withParameters:@{@"item": self.itemSearch.text}
block:^(NSString *result, NSError *error) {
NSLog(@"'%@'", result);
NSData *returnedJSONData = result;
NSError *jsonerror = nil;
NSDictionary *categoryData = [NSJSONSerialization
JSONObjectWithData:returnedJSONData
options:0
error:&jsonerror];
NSArray *resultArray = [categoryData objectForKey:@"results"];
NSDictionary *dictionary1 = [resultArray objectAtIndex:1];
NSNumber *numberOfTopCategories = [dictionary1 objectForKey:@"Number of top categories"];
// NSDictionary *dictionary2 = [resultArray objectAtIndex:2];
// NSNumber *topCategories = [dictionary2 objectForKey:@"Top categories"];
NSDictionary *dictionary3 = [resultArray objectAtIndex:3];
NSNumber *numberOfMatches = [dictionary3 objectForKey:@"Number of matches"];
// NSDictionary *dictionary4 = [resultArray objectAtIndex:4];
// NSNumber *userCategoriesThatMatchSearch = [dictionary4 objectForKey:@"User categories that match search"];
if (!error) {
// if 1 match found clear categoryResults and top2 array
if ([numberOfMatches intValue] == 1 ){
[self performSegueWithIdentifier:@"ShowMatchCenterSegue" sender:self];
}
// if 2 matches found
else if ([numberOfMatches intValue] == 2){
[self performSegueWithIdentifier:@"ShowUserCategoryChooserSegue" sender:self];
//default to selected categories criteria -> send to matchcenter -> clear categoryResults and top2 array
}
// if no matches found, and 1 top category is returned
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 1) {
[self performSegueWithIdentifier:@"ShowCriteriaSegue" sender:self];
}
// if no matches are found, and 2 top categories are returned
else if ([numberOfMatches intValue] == 0 && [numberOfTopCategories intValue] == 2) {
[self performSegueWithIdentifier:@"ShowSearchCategoryChooserSegue" sender:self];
}
}
}];
}
}
我想做的是根据返回的 JSON 的键/值对决定采用哪个 segue。但是,当按下 nextButton 时,我的应用程序崩溃,并返回以下内容:
2014-05-02 14:51:18.623 Parse+Storyboard[1325:60b] '{
results = (
{
"Number of top categories" = 2;
},
{
"Top categories" = (
20349,
9355
);
},
{
"Number of matches" = 0;
},
{
"User categories that match search" = (
);
}
);
}'
2014-05-02 14:51:18.624 Parse+Storyboard[1325:60b] -[__NSDictionaryM bytes]: unrecognized selector sent to instance 0xaa9d090
2014-05-02 14:51:18.639 Parse+Storyboard[1325:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM bytes]: unrecognized selector sent to instance 0xaa9d090'
*** First throw call stack:
(
0 CoreFoundation 0x02a771e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x026358e5 objc_exception_throw + 44
2 CoreFoundation 0x02b14243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x02a6750b ___forwarding___ + 1019
4 CoreFoundation 0x02a670ee _CF_forwarding_prep_0 + 14
5 Foundation 0x0237b4bc -[_NSJSONReader findEncodingFromData:withBOMSkipLength:] + 36
6 Foundation 0x0237b66b -[_NSJSONReader parseData:options:] + 63
7 Foundation 0x0237bc30 +[NSJSONSerialization JSONObjectWithData:options:error:] + 161
8 Parse+Storyboard 0x000039ab __35-[SearchViewController nextButton:]_block_invoke + 203
9 Parse+Storyboard 0x0007b217 __40-[PFTask thenCallBackOnMainThreadAsync:]_block_invoke_2 + 241
10 libdispatch.dylib 0x036877b8 _dispatch_call_block_and_release + 15
11 libdispatch.dylib 0x0369c4d0 _dispatch_client_callout + 14
12 libdispatch.dylib 0x0368a726 _dispatch_main_queue_callback_4CF + 340
13 CoreFoundation 0x02adc43e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
14 CoreFoundation 0x02a1d5cb __CFRunLoopRun + 1963
15 CoreFoundation 0x02a1c9d3 CFRunLoopRunSpecific + 467
16 CoreFoundation 0x02a1c7eb CFRunLoopRunInMode + 123
17 GraphicsServices 0x02cd45ee GSEventRunModal + 192
18 GraphicsServices 0x02cd442b GSEventRun + 104
19 UIKit 0x012f5f9b UIApplicationMain + 1225
20 Parse+Storyboard 0x00002fbd main + 141
21 libdyld.dylib 0x038d1701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我似乎无法弄清楚它指的是哪个选择器,以及为什么无法识别它。
最佳答案
来自错误信息
-[__NSDictionaryM bytes]: unrecognized selector sent to instance ...
和 NSLog() 输出
'{
...
}'
可以看到结果
不是一个字符串(包含 JSON 数据),而是一个 NSDictionary。所以没有必要
使用 NSJSONSerialization:
[PFCloud callFunctionInBackground:@"eBayCategorySearch"
withParameters:@{@"item": self.itemSearch.text}
block:^(NSDictionary *result, NSError *error) {
NSArray *resultArray = [result objectForKey:@"results"];
// ...
}];
另请注意,数组中的第一个数组的索引为零,因此您可能需要
从 resultArray 而不是 1 .. 4 中检索索引为 0 .. 3 的对象。
关于ios - 返回 "unrecognized selector sent to instance"错误的 NSDictionary 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23435544/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que