[英]Why I've set up a prototype cell but nothing showed up?
class DemoTableController: UIViewController,UITableViewDataSource,UITableViewDelegate {
@IBOutlet weak var answerView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
answerView.delegate = self
answerView.dataSource = self
answerView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
return cell
}
我通過StoryBoard將tableView添加到ViewController中的視圖中。
然后,向原型單元中添加一個按鈕。 空白的tableView確實出現了,但是沒有按鈕。
先感謝您。
刪除此行,您的代碼應該可用。這里您不需要registerClass
answerView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
請確保您在情節提要中正確設置了標識符。
必須與您下面的行中的相同:
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
另外,您可能不需要在tableView上(在viewDidLoad中)使用registerClass
方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.