2017-05-11 38 views
0

所以我是新來的iOS應用程序開發,只是基本上試圖創建一個真正的應用程序基於我一直在研究的教程和研究。基本上,我有一個視圖控制器,其次是一個導航控制器和一個表視圖控制器(與靜態單元格)鏈接到該導航控制器。目前的方法顯示空白視圖控制器

這裏的目標是僅僅根據條件呈現表視圖控制器(如果存在的話,當前表視圖控制器,否則不要),並且雖然我可以讓它顯示出來,但它是空白的。它沒有任何我添加的標籤或文本框。

因此,例如,這裏是我在我原來的視圖控制器內。什麼我試圖是檢查是否profileExists如果確實如此,目前的表視圖控制器:

override func viewDidAppear(_ animated: Bool) { 
    super.viewDidAppear(animated) 

    // Check if user has a profile. If so, go to view page; otherwise, bring up new profile view. 
    if profileExists != 1 { 
     // Create new profile page. 
     if let vc = storyboard?.instantiateViewController(withIdentifier: "CreateProfileController") as? CreateProfileViewController { 

      present(vc, animated: true, completion: nil) 
     } 

     print("Need to create new profile page") 
    } 

} 

我有兩個類 - 一個叫CreateProfileViewController(其中我的導航控制器被分配到),和我有一個CreateProfileTableViewController類,這是我的表視圖控制器分配給。我的導航控制器的故事板ID是CreateProfileController

基於該代碼,我期望顯示錶視圖控制器,以及駐留在該表視圖控制器上的標籤和文本框。我可能做錯了什麼地方的表視圖控制器是空的?

編輯:

更新包括CreateProfileTableViewController類:

// 
// CreateProfileTableViewController.swift 
// Steady Marketing 
// 
// Created by Alton on 5/11/17. 
// Copyright © 2017 SteadyMarketing. All rights reserved. 
// 

import UIKit 

class CreateProfileTableViewController: UITableViewController { 


    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Uncomment the following line to preserve selection between presentations 
     // self.clearsSelectionOnViewWillAppear = false 

     // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
     // self.navigationItem.rightBarButtonItem = self.editButtonItem() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    // MARK: - Table view data source 

    override func numberOfSections(in tableView: UITableView) -> Int { 
     // #warning Incomplete implementation, return the number of sections 
     return 0 
    } 

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     // #warning Incomplete implementation, return the number of rows 
     return 0 
    } 

    /* 
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) 

     // Configure the cell... 

     return cell 
    } 
    */ 

    /* 
    // Override to support conditional editing of the table view. 
    override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
     // Return false if you do not want the specified item to be editable. 
     return true 
    } 
    */ 

    /* 
    // Override to support editing the table view. 
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
     if editingStyle == .delete { 
      // Delete the row from the data source 
      tableView.deleteRows(at: [indexPath], with: .fade) 
     } else if editingStyle == .insert { 
      // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
     }  
    } 
    */ 

    /* 
    // Override to support rearranging the table view. 
    override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { 

    } 
    */ 

    /* 
    // Override to support conditional rearranging of the table view. 
    override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { 
     // Return false if you do not want the item to be re-orderable. 
     return true 
    } 
    */ 

    /* 
    // MARK: - Navigation 

    // In a storyboard-based application, you will often want to do a little preparation before navigation 
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     // Get the new view controller using segue.destinationViewController. 
     // Pass the selected object to the new view controller. 
    } 
    */ 

} 
+0

哪裏故事板來自於你的代碼?你也必須打電話給self.present。 – Mannopson

回答

3

在顯示任何基本的tableviewcontroller之前,我們需要做一些事情。

步驟1:

配置數據源和委託。

第2步:

請使用基本數據源2種方法的一些行。

  1. numberofrows。在你的情況下它的0;
  2. cellForAtIndexPath。在你的情況下,我可以看到它的評論。

有很多resources.Right現在這裏是一個鏈接

iOS & Swift Tutorial: UITableViewController-ralfebert

+0

非常感謝您的澄清! – LewlSauce

+1

如果這有幫助,您能接受我的答案嗎? – gEeKyMiNd

+0

我最終刪除了numberofrows和cellforindexpath方法來獲取靜態表來顯示,但我真的很感謝幫助! – LewlSauce

1

好吧,首先您的tableView需要一些章節。至少1個會很好。 之後,你想在每個部分有一些細胞,所以至少在那裏放置1個細胞。

接下來是填充您註釋掉的單元格的部分。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "reuseIdentifier", for: indexPath) 

     // Configure the cell... 
     cell.textLabel = "test" 
     cell.detailTextLabel = "test2" 
     return cell 
    } 
+0

目前,表視圖控制器類只是默認的代碼。那裏還沒有做過任何編碼。所以它的'numberOfSections'和'tableView'函數就是標準文本。這是我失蹤的嗎? – LewlSauce

+0

你能分享代碼嗎? –

+0

已更新的帖子以反映CreateProfileTableViewController的代碼 – LewlSauce

相關問題