我一直在寻找堆栈溢出,但还没有找到解决方案,尽管有很多类似标题的问题。
我在一个 if (time > stopTime) {
stopTime = time
}
# Rip off the header
hdr_size = pkt_size % 512
pkt_size -= hdr_size
# Store received packet's size
recvdSize += pkt_size
}
和两个自定义 printf("\t\tThroughput[kbps] : %.2f\n",(recvdSize/(stopTime-startTime))*(8/1000))
类中有两个UITableView
,用作这两个表的委托和数据源。我设法在表格中填充了数据,但所有单元格在我选择一行后立即消失。这是代码:
UIViewController
甚至没有调用 UITableViewController
和import UIKit
class SearchFiltersViewController: UIViewController {
@IBOutlet weak var typeTable: UITableView!
@IBOutlet weak var regionTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Setup filter and region table
let typeDataSourceAndDelegate = TypeDataSourceAndDelegate()
typeDataSourceAndDelegate.view = self.typeTable
self.typeTable.dataSource = typeDataSourceAndDelegate
self.typeTable.delegate = typeDataSourceAndDelegate
self.typeTable.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
class TypeDataSourceAndDelegate: UITableViewController {
let CELL_IDENTIFIER = "customTypeCell"
var allTypes = [CustomType]()
override func viewWillAppear(animated: Bool) {
if self.allTypes.count == 0 {
self.resetTypes()
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(self.CELL_IDENTIFIER, forIndexPath: indexPath)
let type = self.allTypes[indexPath.row]
cell.textLabel!.text = type.title
return cell
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.allTypes.count
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selectedCell = tableView.cellForRowAtIndexPath(indexPath)
selectedCell?.contentView.backgroundColor = UIColor.hrColors().lightGreyColor()
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
let selectedCell = tableView.cellForRowAtIndexPath(indexPath)
selectedCell?.contentView.backgroundColor = UIColor.hrColors().whiteColor()
}
func resetTypes() {
self.allTypes = [CustomType(id: 0, title: "All Types")]
}
}
方法。帮助