、、、objectivec
2014-07-21 18:02:38.259 Sections[2962:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'must pass a class of kind UITableViewCell'
*** First throw call stack:
(
0 CoreFoundation 0x017375e4 exceptionPreprocess + 180
1 libobjc.A.dylib 0x014ba8b6 objc_exception_throw + 44
2 CoreFoundation 0x017373bb +[NSException raise:format:] + 139
3 UIKit 0x00314e08 -[UITableView registerClass:forCellReuseIdentifier:] + 247
4 Sections 0x000030eb -[BIDViewController searchDisplayController:didLoadSearchResultsTableView:] + 171
5 UIKit 0x005cc0b4 -[UISearchDisplayController searchResultsTableView] + 446
6 UIKit 0x005cd5f4 -[UISearchDisplayController _containerView] + 1031
7 UIKit 0x005c7563 -[UISearchDisplayController setActive:animated:] + 9462
8 UIKit 0x005cad4f -[UISearchDisplayController searchBarTextDidBeginEditing:] + 298
9 UIKit 0x004f52c9 -[UISearchBar(UISearchBarStatic) _searchFieldBeginEditing] + 113
10 libobjc.A.dylib 0x014cc81f -[NSObject performSelector:withObject:] + 70
11 UIKit 0x0022ec8c -[UIApplication sendAction:to:from:forEvent:] + 108
12 UIKit 0x0022ec18 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
13 UIKit 0x003266d9 -[UIControl sendAction:to:forEvent:] + 66
14 UIKit 0x00326a9c -[UIControl _sendActionsForEvents:withEvent:] + 577
15 UIKit 0x0091254e -[UITextField willAttachFieldEditor:] + 685
16 UIKit 0x0032c4d5 -[UIFieldEditor becomeFieldEditorForView:] + 927
17 UIKit 0x00909643 -[UITextField _becomeFirstResponder] + 160
18 UIKit 0x004f841a -[UISearchBarTextField _becomeFirstResponder] + 98
19 UIKit 0x00386585 -[UIResponder becomeFirstResponder] + 400
20 UIKit 0x00289d0b -[UIView(Hierarchy) becomeFirstResponder] + 114
21 UIKit 0x009090e3 -[UITextField becomeFirstResponder] + 51
22 UIKit 0x005ae651 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 135
23 UIKit 0x005b0ba2 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 2640
24 UIKit 0x005a4f8c _UIGestureRecognizerSendActions + 230
25 UIKit 0x005a3c00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
26 UIKit 0x005a566d -[UIGestureRecognizer _delayedUpdateGesture] + 60
27 UIKit 0x005a8bcd ___UIGestureRecognizerUpdate_block_invoke + 57
28 UIKit 0x005a8b4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
29 UIKit 0x0059f248 _UIGestureRecognizerUpdate + 199
30 UIKit 0x0026bd4a -[UIWindow _sendGesturesForEvent:] + 1291
31 UIKit 0x0026cc6a -[UIWindow sendEvent:] + 1030
32 UIKit 0x00240a36 -[UIApplication sendEvent:] + 242
33 UIKit 0x0022ad9f _UIApplicationHandleEventQueue + 11421
34 CoreFoundation 0x016c08af __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15
35 CoreFoundation 0x016c023b __CFRunLoopDoSources0 + 235
36 CoreFoundation 0x016dd30e __CFRunLoopRun + 910
37 CoreFoundation 0x016dcb33 CFRunLoopRunSpecific + 467
38 CoreFoundation 0x016dc94b CFRunLoopRunInMode + 123
39 GraphicsServices 0x036d89d7 GSEventRunModal + 192
40 GraphicsServices 0x036d87fe GSEventRun + 104
41 UIKit 0x0022d94b UIApplicationMain + 1225
42 Sections 0x0000399d main + 141
43 libdyld.dylib 0x01d75701 start + 1
44 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
、、、
如上所示,错误提示,使用的是XCODE5 无法根据错误提示找到出错行,网上有的方法试过不可以。希望知道的同学告知下。谢谢!
Add an exception breakpoint (Add Exception Breakpoint) in Xcode's Breakpoint Navigator, and then set the breakpoint condition to
Exception: Object-C
, so that it can break before the exception is thrown, and you can view the call stack at that time.Note that it is best to turn on this breakpoint when the problematic code is about to be executed, otherwise it will continue to be disturbed by various exceptions.
Your project is called Sections, right?
This is where your exception is thrown:
4 Sections 0x000030eb -[BIDViewController searchDisplayController:didLoadSearchResultsTableView:] + 171
The code offset of the searchDisplayController method of the BIDViewController class is 171 (almost the 170 characters of this method, almost lines 2 and 3. Remember, 171 is not a line number or something).
About iOS exception analysis, it is really a headache at the beginning, because it does not directly tell the developer where the exception is thrown, and sometimes there is even no exception stack. Even if there is an exception stack, it is not easy to understand what it means. In particular, the code offset number is extremely misleading. There are usually many debugging methods, and it would take an entire night to cover them all. The Exception breakpoint answered by Huan Du is one, and of course there is also the log assertion print viewing method, symbolic breakpoint setting, and LLDB debugging tool. Personally, I still prefer the stack analysis method posted in your question. Basically, the problem can be determined based on the class name, method name and code offset.
Regarding the stack report, briefly introduce the meaning of its content:
For example:
4 Sections 0x000030eb -[BIDViewController searchDisplayController:didLoadSearchResultsTableView:] + 171
It includes a total of 5 parts: 4/Sections/0x000030eb/-[BIDView...ew:]/171
Part 1: The stack outputs the sequence number. The larger the sequence number, the earlier the code is called;
Part 2: The framework (library/project) to which the called method belongs. For example, Sections is your project;
Part 3: The memory address of the calling method, which is 0x000030eb
Part 4: Calling method name, this is very important, that is - [BIDViewController searchDisplayController:didLoadSearchResultsTableView:]
Part 5: The code offset after calling the method after compilation. Here again, it is not the line number, but the compiled code offset, but it is basically the same as the number of characters. You can use some text tools to count your methods. The character offset is a rough estimate of the wrong line, and the general error is within 3 to 5 lines.
Here is a little tip to prevent xcode from not printing stack logs:
Add @try@catch on the main method in main.m, like this:
But remember to delete the try catch package before publishing the app, dear~~~
[UITableView registerClass:forCellReuseIdentifier:] Something went wrong here!