【问题标题】:Keep getting breakpoint error when trying to run iOS application on iphone simulator with xcode 5尝试使用 xcode 5 在 iphone 模拟器上运行 iOS 应用程序时不断出现断点错误
【发布时间】:2013-12-19 02:18:35
【问题描述】:

我刚刚开始第一次创建一个新的清单应用程序。

到目前为止,我已经在 main.storyboard 的应用程序 UI 中添加了一个 Table View 对象和 Table View Cell 对象。

然后我转到我的视图控制器头文件并确保将超类类型更改为“UITableViewController”。

然后我转到我的 View Controller 主文件并添加了以下方法:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"];

return cell;

}

我不断收到断点错误,无法让应用程序在 iPhone 模拟器上运行。我已经尝试从头开始并重新创建此应用 3 次,还尝试使用不同的模拟器,但仍然没有任何效果。

每当我尝试运行应用程序时,这就是调试控制台中的最终输出:

libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

另外,这里是我尝试运行程序并遇到断点错误时我的 xcode 的屏幕截图的链接:http://oi40.tinypic.com/25im3kn.jpg

我过去曾多次遇到断点错误,但通常只需转到“调试”>“停用断点”即可修复所有问题,但现在这对我不起作用。

非常感谢您的帮助。

PS。此外,这里是调试控制台日志中的全部输出:

2013-12-18 18:25:55.183 Checklists[4910:70b] *** Assertion failure in -[UITableView     _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-    2903.23/UITableView.m:6246
2013-12-18 18:25:55.190 Checklists[4910:70b] *** Terminating app due to uncaught exception     'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from     tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(
0   CoreFoundation                      0x017385e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x014bb8b6 objc_exception_throw + 44
2   CoreFoundation                      0x01738448 +[NSException     raise:format:arguments:] + 136
3   Foundation                          0x0109bfee -[NSAssertionHandler     handleFailureInMethod:object:file:lineNumber:description:] + 116
4   UIKit                               0x003123d5 __53-[UITableView     _configureCellForDisplay:forIndexPath:]_block_invoke + 426
5   UIKit                               0x0028b3ef +[UIView(Animation)    performWithoutAnimation:] + 82
6   UIKit                               0x0028b438 +[UIView(Animation) _performWithoutAnimation:] + 40
7   UIKit                               0x00312226 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
8   UIKit                               0x0031863d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
9   UIKit                               0x003186f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
10  UIKit                               0x002fc774 -[UITableView _updateVisibleCellsNow:] + 2378
11  UIKit                               0x0030fe95 -[UITableView layoutSubviews] + 213
12  UIKit                               0x00294267 -[UIView(CALayerDelegate)    layoutSublayersOfLayer:] + 355
13  libobjc.A.dylib                     0x014cd81f -[NSObject performSelector:withObject:] + 70
14  QuartzCore                          0x03b462ea -[CALayer layoutSublayers] + 148
15  QuartzCore                          0x03b3a0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
16  QuartzCore                          0x03b46235 -[CALayer layoutIfNeeded] + 160
17  UIKit                               0x0034f613 -[UIViewController window:setupWithInterfaceOrientation:] + 304
18  UIKit                               0x0026e177 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
19  UIKit                               0x0026cd16 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
20  UIKit                               0x0026cbe8 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
21  UIKit                               0x0026cc70 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
22  UIKit                               0x0026bd0a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
23  UIKit                               0x0026bc6c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
24  UIKit                               0x0026c9c3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
25  UIKit                               0x0026ffb6 -[UIWindow setDelegate:] + 449
26  UIKit                               0x00341737 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
27  UIKit                               0x00265c1c -[UIWindow addRootViewControllerViewIfPossible] + 609
28  UIKit                               0x00265d97 -[UIWindow _setHidden:forced:] + 312
29  UIKit                               0x0026602d -[UIWindow _orderFrontWithoutMakingKey] + 49
30  UIKit                               0x0027089a -[UIWindow makeKeyAndVisible] + 65
31  UIKit                               0x00223cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
32  UIKit                               0x002283a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
33  UIKit                               0x0023c87c -[UIApplication handleEvent:withNewEvent:] + 3447
34  UIKit                               0x0023cde9 -[UIApplication sendEvent:] + 85
35  UIKit                               0x0022a025 _UIApplicationHandleEvent + 736
36  GraphicsServices                    0x036df2f6 _PurpleEventCallback + 776
37  GraphicsServices                    0x036dee01 PurpleEventCallback + 46
38  CoreFoundation                      0x016b3d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
39  CoreFoundation                      0x016b3a9b __CFRunLoopDoSource1 + 523
40  CoreFoundation                      0x016de77c __CFRunLoopRun + 2156
41  CoreFoundation                      0x016ddac3 CFRunLoopRunSpecific + 467
42  CoreFoundation                      0x016dd8db CFRunLoopRunInMode + 123
43  UIKit                               0x00227add -[UIApplication _run] + 840
44  UIKit                               0x00229d3b UIApplicationMain + 1225
45  Checklists                          0x00001b7d main + 141
46  libdyld.dylib                       0x01d7670d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

PPS。进行更改后,我的视图控制器主文件现在如下所示:

#import "ChecklistsViewController.h"

@interface ChecklistsViewController ()

@end

@implementation ChecklistsViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"]; if(!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:@"ChecklistItem"]; }

return cell;
}


@end

我仍然收到错误,现在控制台日志显示如下:

2013-12-18 18:42:14.609 Checklists[5014:70b] *** Assertion failure in -[UITableView    _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-    2903.23/UITableView.m:6246
2013-12-18 18:42:14.614 Checklists[5014:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from     tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(
0   CoreFoundation                      0x017395e4 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x014bc8b6 objc_exception_throw + 44
2   CoreFoundation                      0x01739448 +[NSException raise:format:arguments:] + 136
3   Foundation                          0x0109cfee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4   UIKit                               0x003133d5 __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 426
5   UIKit                               0x0028c3ef +[UIView(Animation) performWithoutAnimation:] + 82
6   UIKit                               0x0028c438 +[UIView(Animation) _performWithoutAnimation:] + 40
7   UIKit                               0x00313226 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
8   UIKit                               0x0031963d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
9   UIKit                               0x003196f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
10  UIKit                               0x002fd774 -[UITableView _updateVisibleCellsNow:] + 2378
11  UIKit                               0x00310e95 -[UITableView layoutSubviews] + 213
12  UIKit                               0x00295267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
13  libobjc.A.dylib                     0x014ce81f -[NSObject performSelector:withObject:] + 70
14  QuartzCore                          0x03b472ea -[CALayer layoutSublayers] + 148
15  QuartzCore                          0x03b3b0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
16  QuartzCore                          0x03b47235 -[CALayer layoutIfNeeded] + 160
17  UIKit                               0x00350613 -[UIViewController window:setupWithInterfaceOrientation:] + 304
18  UIKit                               0x0026f177 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212
19  UIKit                               0x0026dd16 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
20  UIKit                               0x0026dbe8 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117
21  UIKit                               0x0026dc70 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67
22  UIKit                               0x0026cd0a __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120
23  UIKit                               0x0026cc6c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400
24  UIKit                               0x0026d9c3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870
25  UIKit                               0x00270fb6 -[UIWindow setDelegate:] + 449
26  UIKit                               0x00342737 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180
27  UIKit                               0x00266c1c -[UIWindow    addRootViewControllerViewIfPossible] + 609
28  UIKit                               0x00266d97 -[UIWindow _setHidden:forced:] +     312
29  UIKit                               0x0026702d -[UIWindow _orderFrontWithoutMakingKey] + 49
30  UIKit                               0x0027189a -[UIWindow makeKeyAndVisible] + 65
31  UIKit                               0x00224cd0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851
32  UIKit                               0x002293a8 -[UIApplication    _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
33  UIKit                               0x0023d87c -[UIApplication     handleEvent:withNewEvent:] + 3447
34  UIKit                               0x0023dde9 -[UIApplication sendEvent:] + 85
35  UIKit                               0x0022b025 _UIApplicationHandleEvent + 736
36  GraphicsServices                    0x036e02f6 _PurpleEventCallback + 776
37  GraphicsServices                    0x036dfe01 PurpleEventCallback + 46
38  CoreFoundation                      0x016b4d65     __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
39  CoreFoundation                      0x016b4a9b __CFRunLoopDoSource1 + 523
40  CoreFoundation                      0x016df77c __CFRunLoopRun + 2156
41  CoreFoundation                      0x016deac3 CFRunLoopRunSpecific + 467
42  CoreFoundation                      0x016de8db CFRunLoopRunInMode + 123
43  UIKit                               0x00228add -[UIApplication _run] + 840
44  UIKit                               0x0022ad3b UIApplicationMain + 1225
45  Checklists                          0x00002aed main + 141
46  libdyld.dylib                       0x01d7770d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

【问题讨论】:

  • 如果您共享出现在“以 NSException 类型的未捕获异常终止”之前出现的日志,那就太好了!
  • Nvinhas 我刚刚用整个日志更新了我原来的问题。

标签: ios objective-c debugging xcode5 breakpoints


【解决方案1】:

问题是代码dequeueReusableCellWithIdentifier 没有返回单元格。

  1. 检查您在 XIB 中的单元格作为重用标识符是否设置为 "ChecklistItem"
  2. 如果dequeueReusableCellWithIdentifier 返回nil,则创建一个新单元格。

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"]; 
    if(!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ChecklistItem"];
    }
    

这应该可以解决您的问题。

【讨论】:

  • 我尝试添加您的解决方案,但仍然出现错误。我已经用您建议的代码更改以及控制台日志现在向我显示的内容更新了我的原始问题。
  • 这很奇怪,因为日志说方法 cellForRowAtIndexPath: 正在返回一个零单元格。您可以在该方法的返回中放置一个断点并查看它是否返回 nil 吗?如果单元格等于 nil,它将进入那个 if 并将创建一个新单元格,因此它不能返回 nil。
  • 我不熟悉使用断点。我刚刚做了q快速谷歌搜索并尝试添加这个:asm(“trap”),我在“return cell;”之前添加了它陈述。我应该使用不同的断点语句吗?我应该在代码的其他地方添加断点语句吗?
  • 您是否正确设置了表的委托和数据源?我推荐你阅读 UITableView 的documentation
  • 在代码行的左边你可以放一个断点。它是一个蓝色箭头。这意味着在运行时,当代码到达该行时,它将停止并向您显示有关变量的信息。然后您可以查看单元格的值并检查它是否为 nil。希望对您有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-27
  • 1970-01-01
  • 1970-01-01
  • 2014-06-02
  • 1970-01-01
  • 2012-10-17
  • 2015-01-24
相关资源
最近更新 更多