在单视图应用程序中创建Apple的官方ToDoList

时间:2014-08-01 15:15:23

标签: xcode ios7

我正在制作待办事项清单,以便在我的单一视图应用程序中,我已经走了很远,我正在进行第三个教程。但是,这是我遇到困难的地方。

我按照书中所做的一切,除了在开头,这是不可能的。

这就是Apple要我在AppDelegate.m文件中输入的内容:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

我已经这样做了,但Xcode不允许我在没有给我错误的情况下放入结尾的花括号。

AppDelegate.m file的开头看起来像这样,我没有收到任何错误:

#import "AppDelegate.h"
#import "LessonController.h"

@implementation AppDelegate

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    LessonController *lessonController = [LessonController sharedController];
    lessonController.managedObjectContext = self.managedObjectContext;
    return YES;
}

当我现在运行应用程序时,它会崩溃,这就是根据调试器的原因:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

这是调试器告诉我的具体内容:

2014-08-01 17:13:49.703 *Name of my app* [18698:60b] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:6509
2014-08-01 17:13:49.707 *Name of my app* [18698:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(
    0   CoreFoundation                      0x01bd11e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x019508e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01bd1048 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x0029e4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   UIKit                               0x007c1d7f __53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 426
    5   UIKit                               0x0073681f +[UIView(Animation) performWithoutAnimation:] + 82
    6   UIKit                               0x00736868 +[UIView(Animation) _performWithoutAnimation:] + 40
    7   UIKit                               0x007c1bd0 -[UITableView _configureCellForDisplay:forIndexPath:] + 108
    8   UIKit                               0x007c913d -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 442
    9   UIKit                               0x007c91f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
    10  UIKit                               0x007aaece -[UITableView _updateVisibleCellsNow:] + 2428
    11  UIKit                               0x007bf6a5 -[UITableView layoutSubviews] + 213
    12  UIKit                               0x0073f964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    13  libobjc.A.dylib                     0x0196282b -[NSObject performSelector:withObject:] + 70
    14  QuartzCore                          0x0472445a -[CALayer layoutSublayers] + 148
    15  QuartzCore                          0x04718244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    16  QuartzCore                          0x047180b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    17  QuartzCore                          0x0467e7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    18  QuartzCore                          0x0467fb85 _ZN2CA11Transaction6commitEv + 393
    19  QuartzCore                          0x0473d5b0 +[CATransaction flush] + 52
    20  UIKit                               0x006edce5 _afterCACommitHandler + 131
    21  CoreFoundation                      0x01b9936e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    22  CoreFoundation                      0x01b992bf __CFRunLoopDoObservers + 399
    23  CoreFoundation                      0x01b77254 __CFRunLoopRun + 1076
    24  CoreFoundation                      0x01b769d3 CFRunLoopRunSpecific + 467
    25  CoreFoundation                      0x01b767eb CFRunLoopRunInMode + 123
    26  GraphicsServices                    0x039995ee GSEventRunModal + 192
    27  GraphicsServices                    0x0399942b GSEventRun + 104
    28  UIKit                               0x006d0f9b UIApplicationMain + 1225
    29  *Name of my app*                     0x0001830d main + 141
    30  libdyld.dylib                       0x02218701 start + 1
    31  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

有关如何解决此问题的任何想法?我

1 个答案:

答案 0 :(得分:1)

您的LessionController是委托或拥有一个对象,该对象是UITableView的委托,它不会从方法tableView:cellForRowAtIndexPath返回有效的UITableViewCell。您应该查看Apple的UITableViews here数据填充指南中列出的示例。