一个视图控制器中的两个表视图,swift

时间:2016-01-21 22:15:12

标签: swift uitableview uiviewcontroller tableview

我的视图控制器有两个表视图。 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
    }
}

}

1 个答案:

答案 0 :(得分:0)

在从Parse检索数据后,请确保重新加载 UITableViews