我真的不知道要搜索什麼關於這個問題,我的搜索嘗試沒有太多的幫助,所以我想我會給這個帖子一個鏡頭。SWIFT UITableView - 在原型單元格中的多行繼續到另一個UITableView
我有一個將有三個行的原型單元格。我想要發生的事情是從每行顯示另一個UITableView的segue - 但我希望保持視圖控制器的數量最小,所以我希望這可以實現只有一個tableViewController。
例如,第1行是「外徑(OD)」,第2行是「重量」,第3行是「內徑(ID)」。這些被定義爲TableViewController文件的類聲明下的常量。
我有一個從上述TableViewController的segue(Modally)到第二個TableViewController,爲此我爲它創建了一個新文件。我在我的類聲明下定義了這個文件中的OD,Weight和ID值作爲常量。
有沒有什麼辦法可以達到這個目的,當用戶點擊OD行時,它只會顯示我在第二個視圖控制器中爲OD定義的值/常量,以及僅顯示何時的Weight和ID常量用戶分別點擊這些行?我的困惑是如何鏈接兩個TableViewControllers,以便它們可以互相交互...但我不確定這是否是所有可能的。我的代碼迄今如下:
表視圖控制器1:
import UIKit
class CapacitiesTableViewController: UITableViewController {
let capacityParameters = ["O.D", "Weight", "I.D"]
@IBAction func cancelSelection(segue: UIStoryboardSegue) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 125.0
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return capacityParameters.count
} else {
return 1
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// init return type of cell
var returnCell: UITableViewCell!
if indexPath.section == 0 { // you can also check for section with section.index
returnCell = tableView.dequeueReusableCellWithIdentifier("capacitiesCell", forIndexPath: indexPath)
let capacityID = capacityParameters[indexPath.row]
returnCell.textLabel?.text = capacityID
return returnCell
} else {
returnCell = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath)
return returnCell
}
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Casing Specification"
} else {
return "Dimension & Strength"
}
}
視圖控制器2:
import UIKit
class CasingSelectionTableViewController: UITableViewController {
let casingOD = ["114.3", "127.0", "139.7", "168.3" , "177.8", "193.7", "219.1", "244.5", "247.6", "273.1", "298.4", "298.4", "339.7", "406.4", "473.0", "508"]
let casingWeight114 = ["14.14", "15.63", "17.26", "20.09", "22.47", "24.70", "26.34", "27.97"]
let casingWeight127 = ["17.11", "19.35", "22.32", "26.79", "31.85", "34.53", "35.86"]
let casingWeight139 = ["20.83", "23.07", "25.30", "29.76", "34.23", "39.28", "44.20", "48.51", "52.53", "56.55", "60.27", "64.14"]
let casingWeight168 = ["19.34", "25.30", "29.76", "32.74", "35.71", "38.69", "41.66", "43.15", "47.62", "50.59"]
let casingWeight177 = ["25.30", "29.76", "34.23", "38.69", "43.16", "47.62", "52.09", "56.55"]
let casingWeight193 = ["35.72", "39.29", "44.20", "50.15", "58.04"]
let casingWeight219 = ["35.72", "41.67", "47.62", "53.57", "59.53"]
let casingWeight244 = ["48.07", "53.57", "59.53", "64.73", "69.94", "79.62"]
let casingWeight247 = ["88.09"]
let casingWeight273 = ["48.74", "60.27", "67.71", "75.90", "82.59"]
let casingWeight298 = ["56.54", "62.50", "69.94", "80.35", "89.28", "96.72", "105.65"]
let casingWeight339 = ["71.43", "81.10", "90.78", "101.19", "107.15"]
let casingWeight406 = ["96.73", "111.61", "125.01", "162.21"]
let casingWeight473 = ["108.76", "116.06", "130.00", "143.59"]
let casingWeight508 = ["139.89", "158.49", "197.93"]
let id114 = ["103.886", "102.921", "101.600", "99.568", "97.180", "95.300", "93.900", "92.400"]
let id127 = ["115.824", "114.148", "111.963", "108.610", "104.800", "104.800", "102.718", "101.600"]
let id139 = ["127.305", "125.730", "124.257", "121.361", "118.618", "114.300", "111.150", "107.950", "104.800", "101.600", "98.450", "95.520"]
let id168 = ["158.800", "155.800", "153.600", "152.100", "150.300", "148.700", "147.000", "146.300", "144.100", "142.100"]
let id177 = ["166.065", "163.982", "161.696", "159.410", "157.074", "154.788", "152.502", "150.368"]
let id193 = ["178.400", "177.000", "174.700", "171.900", "168.300"]
let id219 = ["205.664", "203.632", "201.193", "198.700", "197.400"]
let id244 = ["228.630", "226.590", "224.410", "222.380", "220.500", "216.790"]
let id247 = ["217.400"]
let id273 = ["258.877", "255.270", "252.730", "250.190", "247.904"]
let id298 = ["283.200", "281.500", "279.400", "276.300", "273.600", "271.300", "268.800"]
let id339 = ["322.961", "320.421", "317.881", "315.341", "313.614"]
let id406 = ["387.350", "384.150", "381.254", "373.075"]
let id473 = ["454.000", "453.500", "450.900", "448.400"]
let id508 = ["485.750", "482.600", "475.742"]
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 0
}
/*
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
// Configure the cell...
return cell
}
*/
感謝您的回覆!我會在下班回家時給你一個鏡頭,讓你知道它是怎麼回事 – Matty
當我在我的viewDidLoad中輸入開關盒時,它給了我一個錯誤「enum case'OuterDiameter'在數據類型中找不到!」。 。這可以完全相關的事實,我使用tableViewController而不是使用tableView頂部的viewController? – Matty