【问题标题】:two table view in one view controller, swift一个视图控制器中的两个表视图,快速
【发布时间】:2016-01-21 22:15:12
【问题描述】:

我的视图控制器有两个表视图。 askTable 有效,但bidTable 无效。没有错误出来。

这是它打印的内容。该数组恰好包含我想要的元素。不知道我做错了什么或错过了bidTable。另外,想知道为什么从来没有打印过“Hi”。

askPriceArray: []
bidPriceArray: []
bid: 0 
Above repeat several times
askPriceArray: []
bidPriceArray: ["21"]
ask: 0
askPriceArray: []
bidPriceArray: ["21", "212"]
ask: 0
askPriceArray: ["21"]
bidPriceArray: ["21", "212"]
ask: 1

import UIKit 
class ProductDetailViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
{
    @IBOutlet weak var bidTable: UITableView!
    @IBOutlet weak var askTable: UITableView! 
    var askPriceArray = [String]()
    var bidPriceArray = [String]()
override func viewDidLoad() {
    super.viewDidLoad()
    self.bidTable.dataSource = self
    self.bidTable.delegate = self
    self.askTable.dataSource = self
    self.askTable.delegate = self
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
override func viewDidAppear(animated: Bool) {
.....insert elements to arrays from Parse..........
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    print("askPriceArray: \(self.askPriceArray)")
    print("bidPriceArray: \(self.bidPriceArray)")

    if tableView == self.askTable {
        print("ask: \(askPriceArray.count)")
        return askPriceArray.count
    } else {
        print("bid: \(bidPriceArray.count)")
        return bidPriceArray.count
    }
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if tableView == self.askTable{
        let cell:DetailAskTableViewCell = tableView.dequeueReusableCellWithIdentifier("askCell") as! DetailAskTableViewCell
        cell.askPriceAndQuantity.text = self.askPriceArray[indexPath.row]
        return cell
    } else {
        print("Hi")
        let cell:DetailBidTableViewCell = tableView.dequeueReusableCellWithIdentifier("bidCell") as! DetailBidTableViewCell
        cell.bidPriceAndQuantity.text = self.bidPriceArray[indexPath.row]
        return cell
    }
}

}

【问题讨论】:

  • 我看不出你的代码有什么问题。设置数据时是否重新加载了两个表格视图?
  • 我忘记重新加载bidTable。谢谢。

标签: swift uitableview uiviewcontroller tableview


【解决方案1】:

确保在从 Parse 检索数据后重新加载 两者 UITableViews。

【讨论】:

  • 感谢您的帮助。我忘了重新加载bidTable。再次感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-11
  • 2018-01-30
相关资源
最近更新 更多