简体   繁体   English

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

[英]two table view in one view controller, swift

My view controller has two table views. 我的视图控制器有两个表视图。 The askTable works, but bidTable doesn't work. askTable有效,但bidTable不起作用。 No error comes out. 没有错误出现。

Here is what it prints. 这是它打印的内容。 The array exactly contains the elements I want. 数组恰好包含我想要的元素。 Not sure what I did wrong or miss for bidTable. 不知道我做错了什么或错过了bidTable。 Also, wondering why "Hi" is never printed too. 另外,想知道为什么也从未打印过“ 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
    }
}

} }

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM