当我尝试将tableview添加到新的选项卡式项目时,我收到一个无法解密的错误。
如果我将tableview添加到我的故事板,那么构建应用程序 - 没关系。但是,只要我将“委托”和“dataSource”拖动到带有方框图标的黄色圆圈以将其链接到我的控制器,构建就会失败。为什么会这样?
完全重复步骤:
UITableViewDelegate, UITableViewDataSource
添加到类中。但是,这些都不会显示在自动完成中,就好像控制器不认为它们存在一样。 如果我命令点击一个,我会收到“找不到符号”。 FirstViewController.swift
//
// FirstViewController.swift
// To Do List
//
// Created by Donald Pinkus on 12/14/14.
// Copyright (c) 2014 Don Pinkus. All rights reserved.
//
import UIKit
class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
构建错误
2014-12-14 00:27:04.278 To Do List[11149:566768] -[To_Do_List.FirstViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7faafae29ba0
2014-12-14 00:27:04.285 To Do List[11149:566768] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[To_Do_List.FirstViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7faafae29ba0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105422f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106f66bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010542a04d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010538227c ___forwarding___ + 988
4 CoreFoundation 0x0000000105381e18 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000105f26212 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2353
6 UIKit 0x0000000105f2a098 -[UITableViewRowData numberOfRows] + 97
7 UIKit 0x0000000105d928fc -[UITableView noteNumberOfRowsChanged] + 133
8 UIKit 0x0000000105d9203d -[UITableView reloadData] + 1316
9 UIKit 0x0000000105d9ad86 -[UITableView layoutSubviews] + 31
10 UIKit 0x0000000105d27973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
11 QuartzCore 0x0000000109c25de8 -[CALayer layoutSublayers] + 150
12 QuartzCore 0x0000000109c1aa0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 UIKit 0x0000000105d1b847 -[UIView(Hierarchy) layoutBelowIfNeeded] + 611
14 UIKit 0x0000000105e0ff06 -[UITabBarController _layoutViewController:] + 500
15 UIKit 0x0000000105e10014 -[UITabBarController _wrapperViewForViewController:] + 252
16 UIKit 0x0000000105e16e92 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 378
17 UIKit 0x0000000105e13069 -[UITabBarController _setSelectedViewController:] + 311
18 UIKit 0x0000000105d1f5ce +[UIView(Animation) performWithoutAnimation:] + 65
19 UIKit 0x0000000105e10106 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 221
20 UIKit 0x0000000105e10dfe -[UITabBarController viewWillAppear:] + 121
21 UIKit 0x0000000105dd7821 -[UIViewController _setViewAppearState:isAnimating:] + 487
22 UIKit 0x0000000105d1a136 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 564
23 UIKit 0x0000000105d24aaa -[UIView(Internal) _addSubview:positioned:relativeTo:] + 419
24 UIKit 0x0000000105cf2e37 -[UIWindow addRootViewControllerViewIfPossible] + 456
25 UIKit 0x0000000105cf3041 -[UIWindow _setHidden:forced:] + 247
26 UIKit 0x0000000105cff72c -[UIWindow makeKeyAndVisible] + 42
27 UIKit 0x0000000105caa061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
28 UIKit 0x0000000105cacd2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
29 UIKit 0x0000000105cabbf2 -[UIApplication workspaceDidEndTransaction:] + 179
30 FrontBoardServices 0x0000000108af32a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
31 CoreFoundation 0x000000010535853c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
32 CoreFoundation 0x000000010534e285 __CFRunLoopDoBlocks + 341
33 CoreFoundation 0x000000010534e045 __CFRunLoopRun + 2389
34 CoreFoundation 0x000000010534d486 CFRunLoopRunSpecific + 470
35 UIKit 0x0000000105cab669 -[UIApplication _run] + 413
36 UIKit 0x0000000105cae420 UIApplicationMain + 1282
37 To Do List 0x00000001052403ce top_level_code + 78
38 To Do List 0x000000010524040a main + 42
39 libdyld.dylib 0x0000000107740145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
答案 0 :(得分:0)
您缺少必需的numberOfRowsInSection
方法。
要成为UITableViewDataSource
,您需要实施numberOfRowsInSection
和cellForRowAtIndexPath