简体   繁体   English

'-[__ NSCFString objectForKey:]:无法识别的选择器已发送到实例0x9c515c0'

[英]'-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x9c515c0'

mr problem is------i am getting data from url and the data in arrayobj.when i run this project i am getting this error.what i am do wrong statement or code in project please check connectiondidfinishloading and cellforrowanindexpath . 先生的问题是------我从url和arrayobj中的数据获取数据。当我运行此项目时,我得到此错误。我在项目中执行错误的语句或代码的原因,请检查connectiondidfinishloadingcellforrowanindexpath

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error ;
NSMutableDictionary *dictobj = [NSJSONSerialization JSONObjectWithData:dataobj options:NSJSONReadingMutableContainers error:&error];

newsobj=[dictobj objectForKey:@"news"];

//NSArray *longdeceobj=[newsobj objectForKey:@"long_desc"];

 for (NSDictionary *dict in  newsobj)
 {
    NSDictionary *title=[dict objectForKey:@"title"];
    [arrayobj addObject:title];
 }
 [[self tableobj]reloadData];
}

//this is cell for row at index path code //这是索引路径代码中用于行的单元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString*cellide=@"identifier";
newcustomobj=(newsCustamView *) [tableView dequeueReusableCellWithIdentifier:cellide];
if (newcustomobj==nil)
{
    [[NSBundle mainBundle]loadNibNamed:@"newsCustamView" owner:self options:nil];
}
newcustomobj.newstitle.text=[[[arrayobj objectAtIndex:0]objectForKey:@"news"]objectForKey:@"title"];
return newcustomobj;
}

Error Is: 错误是:

2014-05-23 18:34:04.913 newsdata[6518:90b] -[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x9c515c0
2014-05-23 18:34:04.915 newsdata[6518:90b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x9c515c0'
*** First throw call stack:
(
0   CoreFoundation                      0x01b851e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x015cb8e5 objc_exception_throw + 44
2   CoreFoundation                      0x01c22243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3   CoreFoundation                      0x01b7550b ___forwarding___ + 1019
4   CoreFoundation                      0x01b750ee _CF_forwarding_prep_0 + 14
5   newsdata                            0x00008a13 -[ViewController tableView:cellForRowAtIndexPath:] + 435
6   UIKit                               0x0038411f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
7   UIKit                               0x003841f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
8   UIKit                               0x00365ece -[UITableView _updateVisibleCellsNow:] + 2428
9   UIKit                               0x0037a6a5 -[UITableView layoutSubviews] + 213
10  UIKit                               0x002fa964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
11  libobjc.A.dylib                     0x015dd82b -[NSObject performSelector:withObject:] + 70
12  QuartzCore                          0x03dcd45a -[CALayer layoutSublayers] + 148
13  QuartzCore                          0x03dc1244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
14  QuartzCore                          0x03dc10b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
15  QuartzCore                          0x03d277fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
16  QuartzCore                          0x03d28b85 _ZN2CA11Transaction6commitEv + 393
17  QuartzCore                          0x03d29258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
18  CoreFoundation                      0x01b4d36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
19  CoreFoundation                      0x01b4d2bf __CFRunLoopDoObservers + 399
20  CoreFoundation                      0x01b2b254 __CFRunLoopRun + 1076
21  CoreFoundation                      0x01b2a9d3 CFRunLoopRunSpecific + 467
22  CoreFoundation                      0x01b2a7eb CFRunLoopRunInMode + 123
23  GraphicsServices                    0x03c8f5ee GSEventRunModal + 192
24  GraphicsServices                    0x03c8f42b GSEventRun + 104
25  UIKit                               0x0028bf9b UIApplicationMain + 1225
26  newsdata                            0x000119cd main + 141
27  libdyld.dylib                       0x02330725 start + 0
28  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

The variable dictobj as you are assuming is a NSDictionary, actually it is a NSString. 您所假设的变量dictobj是NSDictionary,实际上是NSString。 Since strings don't respond to the objectForKey: method your app crashed. 由于字符串不响应objectForKey:方法,因此您的应用程序崩溃了。 That is what the error message is telling you. 这就是错误消息告诉您的内容。 Check this link . 检查此链接 for more detail. 有关更多详细信息。

One of the objects that you address, of which you believe it was a dictionary, is actually a string. 您要解决的对象之一(您认为它是字典)实际上是一个字符串。

Especially when parsing JSON or XML: Always double check the class of the object that you fetch and continue working with. 特别是在解析JSON或XML时:始终仔细检查要获取并继续使用的对象的类。 Use [object isKindOfClass:[ClassIThinkItIs class]] 使用[object isKindOfClass:[ClassIThinkItIs class]]

cell.lblTitle.text = [[dataObjectArray objectAtIndex:indexPath.row]title];

cell.datobj.text = [[dataObjectArray objectAtIndex:indexPath.row]date];

cell.longdicobj.text = [[dataObjectArray objectAtIndex:indexPath.row]long_desc];

[cell.imageobj setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[dataObjectArray objectAtIndex:indexPath.row]image_file]]]
      placeholderImage:[UIImage imageNamed:@"songs85-56.png"]];

I think the json data return is a array of news dict for news key dict and every news dict has a title key. 我认为json数据返回是news键字典的新闻字典数组,每个news字典都有title密钥。 So you can try following code to show title in cellForRow : 因此,您可以尝试以下代码在cellForRow显示title

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error ;
NSMutableDictionary *dictobj = [NSJSONSerialization JSONObjectWithData:dataobj options:NSJSONReadingMutableContainers error:&error];

newsobj=[dictobj objectForKey:@"news"];

//NSArray *longdeceobj=[newsobj objectForKey:@"long_desc"];

 for (NSDictionary *dict in  newsobj)
 {
    NSString *title=[dict objectForKey:@"title"]; //title may be NSString type
    [arrayobj addObject:title];
 }
 [[self tableobj] reloadData];
}

in CellForRow 在CellForRow中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString*cellide=@"identifier";
newcustomobj=(newsCustamView *) [tableView dequeueReusableCellWithIdentifier:cellide];
if (newcustomobj==nil)
{
    [[NSBundle mainBundle]loadNibNamed:@"newsCustamView" owner:self options:nil];
}
newcustomobj.newstitle.text= [arrayobj objectAtIndex:0]; //just get title of first news, you can replace 0 with indexpath.row to show news for row.
return newcustomobj;
}

暂无
暂无

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

相关问题 [__NSCFString objectForKey:]:无法识别的选择器已发送到实例0xa6a2750 - [__NSCFString objectForKey:]: unrecognized selector sent to instance 0xa6a2750 终止应用程序-'NSInvalidArgumentException',原因:'-[NSCFString objectForKey:]:无法识别的选择器已发送到实例 - Terminating app - 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance - [__ NSArrayM objectForKey:]:无法识别的选择器发送到目标c中的实例错误 - -[__NSArrayM objectForKey:]: unrecognized selector sent to instance Error in Objective c [__NSCFString timeIntervalSinceReferenceDate]:无法识别的选择器已发送到ABRecordSetValue中的实例0x6c2ccb0 - [__NSCFString timeIntervalSinceReferenceDate]: unrecognized selector sent to instance 0x6c2ccb0 in ABRecordSetValue 目标 c [__NSArrayM objectForKey:]: 无法识别的选择器发送到实例 - objective c [__NSArrayM objectForKey:]: unrecognized selector sent to instance - [__ NSCFArray objectForKey:]:无法识别的选择器发送到实例0x11c824e0 - -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x11c824e0 [__NSCFString count]:无法识别的选择器发送到实例 0x60400043f9c0 - [__NSCFString count]: unrecognized selector sent to instance 0x60400043f9c0 解析json并获取异常,原因:'-[__ NSCFArray objectForKey:]:无法识别的选择器已发送到实例0x7b1c7630 - parsing json and getting exception, reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x7b1c7630 错误:[事件objectForKey:]:无法识别的选择器已发送到实例0x - An error: [Events objectForKey:]: unrecognized selector sent to instance 0x [__NSCFString charValue]:无法识别的选择器发送到实例? - [__NSCFString charValue]: unrecognized selector sent to instance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM