尝试使用xcode 5在iphone模拟器上运行iOS应用程序时,继续获取断点错误

时间:2013-12-19 02:18:35

标签: ios objective-c debugging xcode5 breakpoints

我刚开始创建新的核对清单应用程序。

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

然后我转到我的View Controller头文件,并确保将超类类型更改为“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) 

1 个答案:

答案 0 :(得分:2)

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

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"]; 
    if(!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ChecklistItem"];
    }
    
  3. 那应该解决你的问题。