xcode上的调试方法

iOS 码拜 9年前 (2015-05-07) 900次浏览 0个评论
 

大家好,
    我的一段代码报了如下错误:
SomeTables[2553:207] *** Terminating app due to uncaught exception “”NSInvalidArgumentException””, reason: “”-[NSCFString setFrame:]: unrecognized selector sent to instance 0x4b52550″”

其实我写的代码中并没有setFrame这个方法。堆栈中的调用都是系统的方法,经过反复看代码发现其实错误在这里,我写的一个回调函数的返回值写错了:
– (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;{
return [keys objectAtIndex:section];
}

我错误的把一个非UIView的object返回了。
但是这个是我在看了很多遍代码后找到的错误,请问各位,有没有一个方法可以从zombie、内存、堆栈中发现这个错误的原因呢?
谢谢各位。

自己顶下。。。
将断点设置在异常上,stop on objective-c exceptions
以下是我的堆栈信息,darkdong可以说具体些吗?谢谢~

2011-07-28 17:21:18.709 SomeTables[953:207] -[NSCFString setFrame:]: unrecognized selector sent to instance 0x4b69ac0
2011-07-28 17:21:18.752 SomeTables[953:207] *** Terminating app due to uncaught exception “”NSInvalidArgumentException””, reason: “”-[NSCFString setFrame:]: unrecognized selector sent to instance 0x4b69ac0″”
*** Call stack at first throw:
(
    0   CoreFoundation                      0x00ec7be9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00cbc5c2 objc_exception_throw + 47
    2   CoreFoundation                      0x00ec96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00e39366 ___forwarding___ + 966
    4   CoreFoundation                      0x00e38f22 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x0032664e -[UITableView(UITableViewInternal) _sectionHeaderView:withFrame:forSection:opaque:reuseViewIfPossible:] + 279
    6   UIKit                               0x0031b84a -[UITableView(UITableViewInternal) _sectionHeaderViewWithFrame:forSection:opaque:reuseViewIfPossible:] + 93
    7   UIKit                               0x00333cd2 -[UITableView(_UITableViewPrivate) _updateVisibleHeadersAndFootersNow:] + 2033
    8   UIKit                               0x003306fb -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 2244
    9   UIKit                               0x00328538 -[UITableView layoutSubviews] + 242
    10  QuartzCore                          0x01c66451 -[CALayer layoutSublayers] + 181
    11  QuartzCore                          0x01c6617c CALayerLayoutIfNeeded + 220
    12  QuartzCore                          0x01c5f37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
    13  QuartzCore                          0x01c5f0d0 _ZN2CA11Transaction6commitEv + 292
    14  UIKit                               0x002b419f -[UIApplication _reportAppLaunchFinished] + 39
    15  UIKit                               0x002b4659 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
    16  UIKit                               0x002bedb2 -[UIApplication handleEvent:withNewEvent:] + 1533
    17  UIKit                               0x002b7202 -[UIApplication sendEvent:] + 71
    18  UIKit                               0x002bc732 _UIApplicationHandleEvent + 7576
    19  GraphicsServices                    0x016dea36 PurpleEventCallback + 1550
    20  CoreFoundation                      0x00ea9064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    21  CoreFoundation                      0x00e096f7 __CFRunLoopDoSource1 + 215
    22  CoreFoundation                      0x00e06983 __CFRunLoopRun + 979
    23  CoreFoundation                      0x00e06240 CFRunLoopRunSpecific + 208
    24  CoreFoundation                      0x00e06161 CFRunLoopRunInMode + 97
    25  UIKit                               0x002b3fa8 -[UIApplication _run] + 636
    26  UIKit                               0x002c042e UIApplicationMain + 1160
    27  SomeTables                          0x00002370 main + 102
    28  SomeTables                          0x00002301 start + 53
)
terminate called after throwing an instance of “”NSException”” 

你的目的不就是要出现异常时,程序停在发生异常的地方吗
那就在异常上设置断点xcode3有个选项stop on objective-c exceptions,这样出现异常时,程序停在出问题的代码上,你就能知道是哪里错了
引用 4 楼 darkdong 的回复:

你的目的不就是要出现异常时,程序停在发生异常的地方吗
那就在异常上设置断点xcode3有个选项stop on objective-c exceptions,这样出现异常时,程序停在出问题的代码上,你就能知道是哪里错了

多谢您的回复。
我在系统中设置了stop on objective-c exceptions,但是仍旧没有用。。。仔细看下堆栈发现里面都是系统函数,没有自己写的,所以系统可能就没有办法停在这行exception上面。

29分
1 libobjc.A.dylib 0x00cbc5c2 objc_exception_throw + 47
这一行就是抛出异常,如果设置了断点,应该就会触发.
确认应用是在debug模式下运行,并且查看断点设置里objc_exception_throw libobjc.A.dylib已经打钩
10分
NSInvalidArgumentException  这个就说明了是类形不对的导常了吧, 再打打报错误的位置就ok啦!
10分
很明显,这个方法返回的是一个uiview ,而你返回的肯定是NSString类型,80%是这个类型,如果想指定header的title得换另外个方法

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明xcode上的调试方法
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!