2015-06-28 26 views
0

我有一个设置了视图控制器的故事板。视图控制器分为两部分,一部分是UI日期选择器,另一部分是表视图。当我设置视图控制器为委托和数据源,我得到将表格视图添加到UI视图控制器错误

reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fdb29b4d9e0' 

我的视图控制器通过以下方式

import Foundation 
import UIKit 

class CustomViewController: 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. 
    } 


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{ 

     return 3; 
    } 


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{ 

     var sampleCell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell 

     return sampleCell; 

    } 



} 

回答

2

你确定你的视图的类是否是你的表的类?当我忘记设置视图的课程时,我得到了同样的错误。

+0

,你是对的! – user1801279

+0

很高兴我帮助:)谢谢,现在我可以评论无处不在哈哈:) –

0

做定义你连接到一个IBOutlet属性以下错误故事板/笔尖中的UITableView?视图控制器是否被设置为表视图的委托和数据源?

+0

否在故事板中定义IBOutlets。视图控制器被设置为数据源和委托,当我使用整个视图控制器作为故事板时,它工作正常,当我划分视图控制器时,像我上面提到的 – user1801279

0

您需要设置为UITableView的出口,并且设置代表:

然后在viewDidLoad中设置的tableView的数据源和委托给自己,因为视图控制器实现协议。

相关问题