Swift在表视图控制器中重新加载数据

时间:2016-03-11 22:29:01

标签: ios swift tableview

前言:对于此处的任何错误表示歉意,我对编程和尝试学习仍然很陌生!

在最初将以下数据存储在两个单独的文件中之后,我设法将每个数据集加载到一个单独的表视图中,并在它们之间进行过渡:

class PcTableViewController: UITableViewController {

//SI. Initialises pcs with an empty array of objects to store PC details.
var pcs = [Pc]()

//SI. Creates data in a function "loadTestPcs".
func loadTestPcs()
{
    let pic1 = UIImage(named: "MON1")
    let pc1 = Pc(image: pic1, name: "PC1", graphics: "Radeon R7", cpu: "A6", hdd: 1, ssd:  0, ram:  8, sku: 4643466, price: 499.99)

    let pic2 = UIImage(named: "PC2")
    let pc2 = Pc(image: pic2, name: "PC2", graphics: "Radeon R7", cpu: "A6", hdd: 1, ssd:  0, ram:  8, sku: 4643466, price: 549.99)

    let pic3 = UIImage(named: "PC3")
    let pc3 = Pc(image: pic3, name: "PC3", graphics: "Radeon R7", cpu: "A6", hdd: 1, ssd:  0, ram:  8, sku: 4643466, price: 599.99)

    //SI. adds details stored in pc1,2 and 3 to pcs array.
    //
    pcs += [pc1!, pc2!, pc3!]
}

class monitorTableViewController: UITableViewController {

//SI. Initialises monitors with an empty array of objects to store PC details.
var monitors = [Monitors]()

//SI. Creates data in a function "loadTestMonitors".
func loadTestMonitors()
{
    let pic1 = UIImage(named: "MON1")
    let mon1 = Monitors(image: pic1, name: "Acer Pedator", screenSize: "24", resolution: "A6", details: "IPS ZeroFrame Gaming Widescreen Monitor", sku: 4643466, price: 499.99)

    let pic2 = UIImage(named: "MON2")
    let mon2 = Monitors(image: pic2, name: "PC2", screenSize: "Radeon R7", resolution: "A6", details: "TN G-Sync 144Hz Gaming Widescreen LED Monitor", sku: 4643466, price: 549.99)

    let pic3 = UIImage(named: "MON3")
    let mon3 = Monitors(image: pic3, name: "PC3", screenSize: "Radeon R7", resolution: "A6", details: "IPS SuperWidescreen LED Monitor", sku: 4643466, price: 599.99)

    //SI. adds details stored in pc1,2 and 3 to monitors array.
    //
    monitors += [mon1!, mon2!, mon3!]
}

我现在正试图将所有数据存储在一个位置,其中表格视图(最初显示pc数据)重新加载,因为选择了一行(该行中的项目应存储起来以便稍后在摘要页面上使用)然后应该使用第二组数据加载表视图。

在跟踪食物跟踪器的苹果教程并查看表格视图文档后,我处于停滞状态。

如果有人能够提供帮助,我将非常感激:)

1 个答案:

答案 0 :(得分:0)

你真的不应该重复使用相同的表格视图。而是使用从第一个表视图的单元格到第二个控制器的segue创建两个单独的表视图控制器。