我似乎找不到问题所在,我的代码非常简单和基本,但是,这个错误不允许我度过这个简单的阶段。如果我能在这方面得到一些帮助,那就太好了,谢谢。
import UIKit
class ViewController: UIViewController, UITableViewDelegate , UITableViewDataSource
{
@IBOutlet weak var messageTableView: UITableView!
var messagesArray: [String] = [String]()
override func viewDidLoad()
{
super.viewDidLoad()
self.messageTableView.delegate = self
self.messageTableView.dataSource = self
//add some sample data so that we can see something (because the
array is orginially empty)
self.messagesArray.append("Test 1")
self.messagesArray.append("Test 2")
self.messagesArray.append("Test 3")
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
func tableView(tableView : UITableView , cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
//create a table cell
let cell = self.messageTableView.dequeueReusableCellWithIdentifier("MessageCell") as UITableViewCell
//Customize the cell
cell.textLabel?.text = self.messagesArray[indexPath.row]
//Return the cell
return cell
}
func tableView( tableView: UITableView , numberOfRowsInSection section: Int )
return messagesArray.count
}
}
最佳答案
tableView:cellForRowAtIndexPath:
和 tableView:numberOfRowsInSection:
嵌套在 didReceiveMemoryWarning
内部。
您需要将倒数第二个右括号移到该行之后:
// Dispose of any resources that can be recreated.
关于swift - 类型 'ViewController' 不符合协议(protocol) 'UITableViewDataSource' 我不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31704333/