Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当我在搜索栏中输入第一个字符时,我的应用程序崩溃_Ios_Uitableview_Uisearchbar_Uisearchbardisplaycontrol - Fatal编程技术网

Ios 当我在搜索栏中输入第一个字符时,我的应用程序崩溃

Ios 当我在搜索栏中输入第一个字符时,我的应用程序崩溃,ios,uitableview,uisearchbar,uisearchbardisplaycontrol,Ios,Uitableview,Uisearchbar,Uisearchbardisplaycontrol,我已经在tableview中解析了JSON,我想实现搜索栏来过滤大量数据。我已经尝试从中实现搜索栏 但它崩溃了 -(void)parsingmethod{ NSString *string = [NSString stringWithFormat:@"HEREISMYJSONURL"]; NSURL *url = [NSURL URLWithString:string]; NSURLRequest *request = [NSURLRequest requestWithURL

我已经在tableview中解析了
JSON
,我想实现搜索栏来过滤大量数据。我已经尝试从中实现搜索栏

但它崩溃了

-(void)parsingmethod{

   NSString *string = [NSString stringWithFormat:@"HEREISMYJSONURL"];
   NSURL *url = [NSURL URLWithString:string];
   NSURLRequest *request = [NSURLRequest requestWithURL:url];
   AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
   operation.responseSerializer = [AFJSONResponseSerializer serializer];
   [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

   self.json=[responseObject valueForKey:@"name"];
   self.filteredCandyArray = [NSMutableArray arrayWithCapacity:[candyArray count]];
   self.filteredArray=[NSMutableArray arrayWithArray:self.json];
   NSLog(@"self.flteredarray=%@",self.filteredArray);
   self.current_address = [responseObject valueForKey:@"current_address"];

   [self.tableView reloadData];

  } failure:^(AFHTTPRequestOperation *operation, NSError *error){
    NSLog(@"Oops, something went wrong: %@", [error localizedDescription]);
  }];
  [operation start]; 
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if ( cell == nil ) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        cell.textLabel.text =[self.filteredArray objectAtIndex:indexPath.row];
    } else {
        cell.textLabel.text =[self.json objectAtIndex:indexPath.row];
    }
    cell.detailTextLabel.text=[self.current_address objectAtIndex:indexPath.row];
    return cell;
}
内容过滤和委托方法也可以从

在我的崩溃日志下面

  ***** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0xcc515f0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.'
*** First throw call stack:
(
    0   CoreFoundation                      0x021af1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0199c8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0223efe1 -[NSException raise] + 17
    3   Foundation                          0x0165cc7a -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
    4   Foundation                          0x015c9dfd _NSGetUsingKeyValueGetter + 81
    5   Foundation                          0x015c9437 -[NSObject(NSKeyValueCoding) valueForKey:] + 260
    6   Foundation                          0x0159a465 -[NSFunctionExpression expressionValueWithObject:context:] + 1260
    7   Foundation                          0x016202c1 -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 248
    8   Foundation                          0x016201c1 -[NSPredicate evaluateWithObject:] + 48
    9   Foundation                          0x01620141 _filterObjectsUsingPredicate + 418
    10  Foundation                          0x0161fefa -[NSArray(NSPredicateSupport) filteredArrayUsingPredicate:] + 328
    11  LuckyHR                             0x00043995 -[NameListTableViewController filterContentForSearchText:scope:] + 245
    12  LuckyHR                             0x00043bf2 -[NameListTableViewController searchDisplayController:shouldReloadTableForSearchString:] + 386
    13  UIKit                               0x00a1eb37 -[UISearchDisplayController searchBar:textDidChange:] + 128
    14  UIKit                               0x0093dc56 -[UISearchBar(UISearchBarStatic) _searchFieldEditingChanged] + 178
    15  libobjc.A.dylib                     0x019ae82b -[NSObject performSelector:withObject:] + 70
    16  UIKit                               0x0065e3b9 -[UIApplication sendAction:to:from:forEvent:] + 108
    17  UIKit                               0x0065e345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    18  UIKit                               0x0075fbd1 -[UIControl sendAction:to:forEvent:] + 66
    19  UIKit                               0x0075ffc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
    20  UIKit                               0x00d8529d -[UITextField fieldEditorDidChange:] + 221
    21  UIKit                               0x00765db4 -[UIFieldEditor textInputDidChange:] + 58
    22  UIKit                               0x00d931b3 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 118
    23  UIKit                               0x00d95090 -[UITextInputController _insertText:fromKeyboard:] + 768
    24  UIKit                               0x00d95954 -[UITextInputController insertText:] + 372
    25  UIKit                               0x00768a64 -[UIFieldEditor insertText:] + 1086
    26  UIKit                               0x00d88ffa -[UITextField insertText:] + 59
    27  UIKit                               0x00848760 -[UIKeyboardImpl insertText:] + 87
    28  UIKit                               0x00859ea4 -[TIKeyboardOperationInsertText(UIKeyboardImpl) main] + 83
    29  Foundation                          0x01670c79 -[__NSOperationInternal _start:] + 671
    30  Foundation                          0x015ed9c8 -[NSOperation start] + 83
    31  UIKit                               0x00846d4d -[UIKeyboardImpl performOperations:] + 153
    32  UIKit                               0x00844f8e -[UIKeyboardImpl continueHandleKeyboardInputWithOperations:] + 75
    33  UIKit                               0x00844ddc __73-[UIKeyboardImpl replyHandlerForHandleKeyboardInputWithExecutionContext:]_block_invoke_2 + 44
    34  UIKit                               0x00dae978 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
    35  libobjc.A.dylib                     0x019ae82b -[NSObject performSelector:withObject:] + 70
    36  Foundation                          0x015f0e48 __NSThreadPerformPerform + 285
    37  CoreFoundation                      0x0213877f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    38  CoreFoundation                      0x0213810b __CFRunLoopDoSources0 + 235
    39  CoreFoundation                      0x021551ae __CFRunLoopRun + 910
    40  CoreFoundation                      0x021549d3 CFRunLoopRunSpecific + 467
    41  CoreFoundation                      0x021547eb CFRunLoopRunInMode + 123
    42  GraphicsServices                    0x031d45ee GSEventRunModal + 192
    43  GraphicsServices                    0x031d442b GSEventRun + 104
    44  UIKit                               0x0065cf9b UIApplicationMain + 1225
    45  LuckyHR                             0x000499fd main + 141
    46  libdyld.dylib                       0x0392a70d start + 1
    47  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) *
****由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[valueForUndefinedKey:]:此类不符合密钥名称的键值编码。”
***第一次抛出调用堆栈:
(
0 CoreFoundation 0x021af1e4例外预处理+180
1 libobjc.A.dylib 0x0199c8e5 objc_异常_抛出+44
2芯基础0x0223efe1-[N异常升高]+17
3基金会0x0165cc7a- [NSObjuts:NSKEY ValueCudid)ValueFunDealdKEY::+ 282
4基金会0x015C9DFD,NoGestUsKiValueGeTeter + 81
5基金会0x015C9437 - [ NSObjices(NSKEY ValueCudid)ValueFoiKe:] + 260
6基金会0x0159A465 - [ NSCONTRONTRONEXPRESS VALIONEXPRESS VALION:对象:上下文:] + 1260
7基金会0x016202C1- [ NSimeSusion谓词评价对象:替换变量:] + 248
8基金会0x016201C1- [ NSPReDATATE评估对象:] + 48
9基金会0x01620141,过滤对象,谓词+ 418
10基金会0x0161FEFA- [ NSARTRAP(NSPReDeCATESUpPATH)过滤文件ADRayAuthEngutial:+ ] 328
11 LuckyHR 0x00043995-[NameListTableViewController filterContentForSearchText:scope:][245
12 LuckyHR 0x00043bf2-[NameListTableViewController搜索显示控制器:应重新加载TableForSearchString:+386
13 UIKit 0x00a1eb37-[UISearchDisplayController搜索栏:textDidChange:+128
14 UIKit 0x0093dc56-[UISearchBar(UISearchBarStatic)\u searchFieldEditingChanged]+178
15 libobjc.A.dylib 0x019ae82b-[NSObject性能选择器:withObject:+70
16 UIKit 0x0065e3b9-[UIApplication sendAction:to:from:forEvent:][108
17 UIKit 0x0065e345-[UIApplication sendAction:toTarget:fromSender:forEvent:][61
18 UIKit 0x0075fbd1-[UIControl发送操作:发送到:forEvent:+66
19 UIKit 0x0075ffc6-[UIControl\u发送操作预防:带事件:][577
20 UIKit 0x00d8529d-[UITextField FieldEditordChange:+221
21 UIKit 0x00765db4-[UIFieldEditor textInputDidChange:+58
22 UIKit 0x00d931b3-[UITExputcontroller\u sendDelegateChangeNotificationsForText:选择:][118
23 UIKit 0x00d95090-[UIT输入控制器\u插入文本:来自键盘:][768
24 UIKit 0x00d95954-[UIT输入控制器插入文本:+372
25 UIKit 0x00768a64-[UIFieldEditor insertText:+1086
26 UIKit 0x00d88ffa-[UITextField insertText:+59
27 UIKit 0x00848760-[UIKeyboardImpl insertText:+87
28 UIKit 0x00859ea4-[TIKeyboardOperationInsertText(UIKeyboardImpl)main]+83
29基金会0x01670C79- [α,NS-操作内部启动:] + 671
30基金会0x015ED9C8- [操作开始] + 83
31 UIKit 0x00846d4d-[UIKeyboardImpl性能操作:][153
32 UIKit 0x00844f8e-[UIKeyboardImpl continueHandleKeyboardInputWithOperations:+75
33 UIKit 0x00844ddc\uuu 73-[UIKeyboardImpl replyHandlerForHandleKeyboardInputWithExecutionContext:][uBlock\uInvoke\u2+44
34 UIKit 0x00dae978-[UIKeyboardTaskQueue continueExecutionOnMainThread]+402
35 libobjc.A.dylib 0x019ae82b-[NSObject性能选择器:withObject:+70
36基金会0x015F0E48,NSTReRePrimeExp+ 285
37 CoreFoundation 0x0213877f\uuu CFRUNLOOP\u正在调用\u OUT\u以执行\u功能\uuu+15
38 CoreFoundation 0x0213810b__CFRunLoopDoSources0+235
39 CoreFoundation 0x021551ae\uuu CFRunLoopRun+910
40 CoreFoundation 0x021549d3 CFRunLoopRunSpecific+467
41 CoreFoundation 0x021547eb CFRUNLOOPSRUNINMODE+123
42图形服务0x031d45ee GSEventRunModal+192
43图形服务0x031d442b GSEventRun+104
44 UIKit 0x0065cf9b UIApplicationMain+1225
45 LuckyHR 0x000499fd干管+141
46 libdyld.dylib 0x0392a70d开始+1
47°?0x00000001 0x0+1
)
libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)*

我看了这里贴的类似问题,但仍然没有弄明白。

上面写得很清楚:

3   Foundation                          0x0165cc7a -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 282
4   Foundation                          0x015c9dfd _NSGetUsingKeyValueGetter + 81
5   Foundation                          0x015c9437 -[NSObject(NSKeyValueCoding) valueForKey:] + 260

您请求的密钥不存在,因此无法使用。

请正确设置代码格式,并包含您收到的错误