swift中的一个视图上的两个表

我有以下代码显示在一个视图中从两个不同数组填充的两个表:
@IBOutlet var RFTable: UITableView
    func tableView(tableView: UITableView!,didSelectRowAtIndexPath indexPath: NSIndexPath!) {

    }
    override func viewDidLoad() {
        super.viewDidLoad()

        self.RFTable.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell")
    }
    func tableView(tableView: UITableView!,numberOfRowsInSection section: Int) -> Int {
        return self.RFArray.count;
    }
    func tableView(tableView: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) ->     UITableViewCell! {
        var cell:UITableViewCell = self.RFTable.dequeueReusableCellWithIdentifier("cell") as     UITableViewCell

        cell.textLabel.text = String(self.RFArray[indexPath.row])

        return cell
    }

    @IBOutlet var IMProdTable: UITableView
    func tableView2(IMProdTable: UITableView!,didSelectRowAtIndexPath indexPath: NSIndexPath!)     {

    }
    override func viewDidLoad() {
        super.viewDidLoad()

        self.IMProdTable.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell2")
    }
    func tableView2(IMProdTable: UITableView!,numberOfRowsInSection section: Int) -> Int {
    return self.IMProdArray.count;
    }
    func tableView2(IMProdTable: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) ->     UITableViewCell! {
        var cell2:UITableViewCell = self.IMProdTable.dequeueReusableCellWithIdentifier("cell2") as UITableViewCell

        cell2.textLabel.text = String(self.IMProdArray[indexPath.row])

        return cell2
    }

我得到了第一个表,然后复制并粘贴了文本,替换了数组名称和tableview名称,并连接了委托和数据源.但是,Xcode在第二个(粘贴的)代码上显示“viewdidload的无效重新声明”.如果我将此替换为’fund loadView(){‘而不是viewdidload应用程序构建.当我测试它时,两个表都查看完全相同的数据,即’RFArray’中的数据.我是非常新的编码,看不到我做了什么,请帮忙.

@IBOutlet var RFTable: UITableView
@IBOutlet var IMProdTable: UITableView

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

}

override func viewDidLoad() {
    super.viewDidLoad()

    self.RFTable.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell")
    self.IMProdTable.registerClass(UITableViewCell.self,forCellReuseIdentifier: "cell2")
}

func tableView(tableView: UITableView!,numberOfRowsInSection section: Int) -> Int {
  if tableView == RFTable {
    return self.RFArray.count;
  } else {
    return self.IMProdArray.count;
  }
}

func tableView(tableView: UITableView!,cellForRowAtIndexPath indexPath: NSIndexPath!) ->     UITableViewCell! {
  if tableView == RFTable {
    var cell:UITableViewCell = self.RFTable.dequeueReusableCellWithIdentifier("cell") as     UITableViewCell
    cell.textLabel.text = String(self.RFArray[indexPath.row])
    return cell
  } else {
    var cell2:UITableViewCell = self.IMProdTable.dequeueReusableCellWithIdentifier("cell2") as UITableViewCell
    cell2.textLabel.text = String(self.IMProdArray[indexPath.row])
    return cell2  
    }
}

只需快速编辑.您需要保持委托和数据源方法相同,并检查哪个TableView实例实际发送消息.

您不能在派生类中两次覆盖相同的方法.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...