2016-04-09 105 views
2

我得到了一個錯誤,由tableView的IBoutlet說「不能用存儲的屬性覆蓋」tableView「」。我不太確定這意味着什麼,任何類型的幫助將不勝感激。 進口的UIKit表視圖不能正常工作

class UsersViewController: UITableViewController { 

    @IBOutlet var tableView: UITableView! 

    var users = ["Marc", "Mark" , "Louise", "Ahinga", "Amossi", "Kalenga"] 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

    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 { 
     return 3 
    } 

    override func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell { 
     let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! userCell 
    } 

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

    } 
} 

回答

1

一個UITableViewController有自帶的一個UITableView,恰當地命名爲tableView。在你粘貼的代碼中,你增加了一個額外的UITableView給它,並給它同名。這正是編譯器所抱怨的。

從理論上講,當您使用故事板上的普通香草UITableViewController時,不應將該錶鏈接到IBOutlet。這是照顧。

如果您正在構建更復雜的東西,需要額外的UITableViewController而不是該類在故事板中提供的東西,那麼您應該以不同的方式命名它。

1

你必須設置,因爲它是delegatedataSourceviewDidLoad()這樣

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.tableView.delegate = self 
    self.tableView.dataSource = self 
} 
+0

它不應該是這樣。 UITableViewController默認遵循UITableViewDelegate和UITableViewDataSource協議,並且它的tableView被設置爲它。 – catalandres