我最近遇到了一个问题。ViewController不符合协议UITableViewDataSource
我会后一些代码了。尝试从互联网的方法,但没有成功。另外,我已将这两个表格链接到View Controller。
下面是一些代码。
class ViewController2: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var carImageView: UIImageView!
@IBOutlet weak var pieseDorite: UITableView!
@IBOutlet weak var pieseDisponibile: UITableView!
var fullNameArr : [String] = [] // i populate the string in a action button, no problem with the arrays
var fullNameArrDorit : [String] = []
override func viewDidLoad()
{
super.viewDidLoad()
carImageView.image = UIImage(named: ("simplu"))
carImageView.contentMode = .ScaleAspectFit
pieseDisponibile.delegate = self
pieseDisponibile.dataSource = self
self.view.addSubview(pieseDisponibile)
pieseDorite.delegate = self
pieseDorite.dataSource = self
self.view.addSubview(pieseDorite)
}
func tableView(pieseDisponibile: UITableView, numberOfRowsInSection section:Int) -> Int
{
return fullNameArr.count
}
func tableView(pieseDisponibile: UITableView, pieseDorite: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")
cell.textLabel!.text = String(fullNameArr[indexPath.row])
return cell
}
func tableView2(pieseDorite: UITableView, numberOfRowsInSection section:Int) -> Int
{
return fullNameArrDorit.count
}
func tableView2(pieseDorite: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell2:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell2")
cell2.textLabel!.text = String(fullNameArrDorit[indexPath.row])
return cell2
}
}
此外,试图添加所有其他功能,问题依然存在。我想我已经把不好的东西联系起来了,我不知道。
更换所有tableview2到tableview中,您可以通过同一个数据源和委托方法标签标识的tableview –