Ios 无法将标识符为的单元格出列

Ios 无法将标识符为的单元格出列,ios,objective-c,uitableview,Ios,Objective C,Uitableview,以下是导致问题的方法: -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TableCell"; TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier

以下是导致问题的方法:

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TableCell";
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier 
                                                      forIndexPath:indexPath];

    // Configure the cell...
    int row = [indexPath row];

    Books *book = [myBooks objectAtIndex:row];
    cell.bookName.text = book.bookName;

    return cell;
}
完整日志:

2014-02-05 23:19:09.458 Books[1425:a0b] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:5251 2014-02-05 23:19:09.471 Books[1425:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier TableCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' *** 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 0x0109d23e -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 4 UIKit 0x003135e3 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 170 5 Books 0x000032df -[TableViewController tableView:cellForRowAtIndexPath:] + 127 6 UIKit 0x0031dd2f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412 7 UIKit 0x0031de03 -[UITableView _createPreparedCellForGlobalRow:] + 69 8 UIKit 0x00302124 -[UITableView _updateVisibleCellsNow:] + 2378 9 UIKit 0x003155a5 -[UITableView layoutSubviews] + 213 10 UIKit 0x00299dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 11 libobjc.A.dylib 0x014ce81f -[NSObject performSelector:withObject:] + 70 12 QuartzCore 0x03af372a -[CALayer layoutSublayers] + 148 13 QuartzCore 0x03ae7514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 14 QuartzCore 0x03af3675 -[CALayer layoutIfNeeded] + 160 15 UIKit 0x00354ca3 -[UIViewController window:setupWithInterfaceOrientation:] + 304 16 UIKit 0x00273d27 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 5212 17 UIKit 0x002728c6 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82 18 UIKit 0x00272798 -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 117 19 UIKit 0x00272820 -[UIWindow _setRotatableViewOrientation:duration:force:] + 67 20 UIKit 0x002718ba __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 120 21 UIKit 0x0027181c -[UIWindow _updateToInterfaceOrientation:duration:force:] + 400 22 UIKit 0x00272573 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 870 23 UIKit 0x00275b66 -[UIWindow setDelegate:] + 449 24 UIKit 0x00346dc7 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 180 25 UIKit 0x0026b7cc -[UIWindow addRootViewControllerViewIfPossible] + 609 26 UIKit 0x0026b947 -[UIWindow _setHidden:forced:] + 312 27 UIKit 0x0026bbdd -[UIWindow _orderFrontWithoutMakingKey] + 49 28 UIKit 0x0027644a -[UIWindow makeKeyAndVisible] + 65 29 UIKit 0x002298e0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1851 30 UIKit 0x0022dfb8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824 31 UIKit 0x0024242c -[UIApplication handleEvent:withNewEvent:] + 3447 32 UIKit 0x00242999 -[UIApplication sendEvent:] + 85 33 UIKit 0x0022fc35 _UIApplicationHandleEvent + 736 34 GraphicsServices 0x0368c2eb _PurpleEventCallback + 776 35 GraphicsServices 0x0368bdf6 PurpleEventCallback + 46 36 CoreFoundation 0x016b4dd5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53 37 CoreFoundation 0x016b4b0b __CFRunLoopDoSource1 + 523 38 CoreFoundation 0x016df7ec __CFRunLoopRun + 2156 39 CoreFoundation 0x016deb33 CFRunLoopRunSpecific + 467 40 CoreFoundation 0x016de94b CFRunLoopRunInMode + 123 41 UIKit 0x0022d6ed -[UIApplication _run] + 840 42 UIKit 0x0022f94b UIApplicationMain + 1225 43 Books 0x000038bd main + 141 44 libdyld.dylib 0x01d75725 start + 0 45 ??? 0x00000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 2014-02-05 23:19:09.458图书[1425:a0b]***在[UITableView dequeueReusableCellWithIdentifier:forIndexPath:],/SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:5251中断言失败 2014-02-05 23:19:09.471 Books[1425:a0b]***由于未捕获的异常“NSInternalInconsistenceException”而终止应用程序,原因:“无法将具有标识符的单元格出列TableCell-必须为标识符注册nib或类,或连接故事板中的原型单元格” ***第一次抛出调用堆栈: ( 0 CoreFoundation 0x017395e4例外预处理+180 1 libobjc.A.dylib 0x014bc8b6 objc_异常_抛出+44 2 CoreFoundation 0x01739448+[N异常提升:格式:参数:][136 3基金会0x0109D2E-[NSRealStutsHuffer-HeaveReuluIn方法:对象:文件:文件号:描述:] + 116 4 UIKit 0x003135e3-[UITableView dequeueReusableCellWithIdentifier:forIndexPath:+170 5本书0x000032df-[tableView控制器tableView:cellForRowAtIndexPath:+127 6 UIKit 0x0031dd2f-[UITableView\u createPreparedCellForGlobalRow:withIndexPath:+412 7 UIKit 0x0031de03-[UITableView\u createPreparedCellForGlobalRow:+69 8 UIKit 0x00302124-[UITableView\u updateVisibleCellsNow:+2378 9 UIKit 0x003155a5-[UITableView布局子视图]+213 10 UIKit 0x00299dd7-[UIView(CALayerDelegate)布局层的子层:+355 11 libobjc.A.dylib 0x014ce81f-[NSObject性能选择器:withObject:+70 12夸脱芯0x03af372a-[CALayer布局子层]+148 13夸脱核心0x03ae7514 _Zn2CA516层布局_如果需要PNS 11交易+380 14夸脱芯0x03af3675-[CALayer LayoutifNeed]+160 15 UIKit 0x00354ca3-[UIViewController窗口:设置接口方向:][304 16 UIKit 0x00273d27-[UIWindow\u setRotatableClient:TooOrientation:updateStatusBar:duration:force:isRotating:+5212 17 UIKit 0x002728c6-[UIWindow\u setRotatableClient:TooOrientation:updateStatusBar:duration:force:+82 18 UIKit 0x00272798-[UIWindow\u setRotatableViewOrientation:updateStatusBar:duration:force:+117 19 UIKit 0x0027220-[UIWindow\u setRotatableViewOrientation:持续时间:强制:+67 20 UIKit 0x002718ba-57-[UIWindow-updateToInterfaceOrientation:duration:force:][U block\U invoke+120 21 UIKit 0x0027181c-[UIWindow\u updateToInterfaceOrientation:duration:force:+400 22 UIKit 0x00272573-[UIWindow setAutorotates:forceUpdateInterfaceOrientation:+870 23 UIKit 0x00275b66-[UIWindow setDelegate:+449 24 UIKit 0x00346dc7-[UIViewController\u TryBecomerootViewController窗口:][180 25 UIKit 0x0026b7cc-[UIWindow AddRootViewControllerServiceWifPossible]+609 26 UIKit 0x0026b947-[UIWindow\u setHidden:强制:][312 27 UIKit 0x0026bbdd-[UIWindow\u OrderFront不带制作键]+49 28 UIKit 0x0027644a-[UIWindow makeKeyAndVisible]+65 29 UIKit 0x002298e0-[UIApplication\u CallInitializationDelegatesForRL:有效负载:挂起:][1851 30 UIKit 0x0022dfb8-[UIApplication-runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:+824 31 UIKit 0x002422C-[UIApplication handleEvent:withNewEvent:][3447 32 UIKit 0x00242999-[UIApplication sendEvent:+85 33 UIKit 0x0022fc35 _UIApplicationHandleEvent+736 34图形服务0x0368c2eb _PurpleEventCallback+776 35图形服务0x0368bdf6 PurpleEventCallback+46 36 CoreFoundation 0x016b4dd5\uuuu CFRUNLOOP\u正在调用\u OUT\u到\u A\u SOURCE1\u PERFORM\u函数\uuu+53 37 CoreFoundation 0x016b4b0b\uu CFRunLoopDoSource1+523 38 CoreFoundation 0x016df7ec\uuu CFRunLoopRun+2156 39 CoreFoundation 0x016deb33 CFRunLoopRunSpecific+467 40 CoreFoundation 0x016de94b CFRUNLOOPSRUNINMODE+123 41 UIKit 0x0022d6ed-[UIApplication\u run]+840 42 UIKit 0x0022f94b UIApplicationMain+1225 43本0x000038bd主目录+141 44 libdyld.dylib 0x01d75725开始+0 45°?0x00000001 0x0+1 ) libc++abi.dylib:以NSException类型的未捕获异常终止
(lldb)来自文件:

重要提示:必须使用 registerNib:forCellReuseIdentifier:或 调用此之前的registerClass:forCellReuseIdentifier:方法 方法

您需要将该单元注册为该标识符的可用类。初始化
UITableView
(可能在
viewDidLoad
中)后调用此函数

这假设
CellIdentifier
已移动到可以从此处访问的位置。

尝试以下操作:

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

static NSString *CellIdentifier = @"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(!cell)
{
    cell = [[[TableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell...
int row = [indexPath row];

Books *book = [myBooks objectAtIndex:row];
cell.bookName.text = book.bookName;

return cell;
}

您可以像这样使用故事板直接设置标识符

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TableCell"; TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(!cell) { cell = [[[TableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell... int row = [indexPath row]; Books *book = [myBooks objectAtIndex:row]; cell.bookName.text = book.bookName; return cell; }