我有一个父视图UIViewController(在故事板上),一个带有.xib的TableViewController和带有.xib的TableViewCell.我正在尝试将DataSource连接到TableView,但是它给了我一个错误:
"TableView1"与协议"UITableViewDataSource"的冗余一致性
'TableView1'继承了来自超类的协议'UITableViewDataSource'的一致性.
如果不在类附近添加dataSource并尝试它class TableView1: UITableViewController {..
,它不会给我任何错误,在模拟器中,当我向下滚动时,我可以看到表视图错觉.
但是,当我尝试添加dataSource时,它给了我这些错误.
我设置它的路径......:
按住Ctrl键并从xib拖动到TableView1并将其连接为 Globals
在xib文件中,我连接了DataSource和Delegate
最后,我的TableView1:
class TableView1: UITableViewController, UITableViewDataSource {
错误在这里..
@IBOutlet var GlobalsTableView: UITableView! var results: [AnyObject]? = [] override func viewDidLoad() { super.viewDidLoad() print("A") } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { // #warning Incomplete implementation, return the number of sections return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete implementation, return the number of rows return self.results?.count ?? 0 } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! DogTableViewCell return cell } }
请注意,在TableView1.xib中,我无法选择TableView1
自定义类 - >类(但我不认为这是必要的).
当一个类继承时UITableViewController
,它默认符合UITableViewDataSource
&UITableViewDelegate
,你不需要显式指定它.
你需要遵守UITableViewDataSource
并且UITableViewDelegate
只有当你嵌入UITableView
一个UIViewController
.