【问题标题】:Why are the changes made in Xcode Storyboard not getting reflected on Simulator / Device?为什么 Xcode Storyboard 中所做的更改没有反映在模拟器/设备上?
【发布时间】:2019-04-02 23:57:06
【问题描述】:

我使用情节提要设计了一个自定义表格视图。当应用程序在模拟器或 iPhone 上运行时,更改不会显示。它仍然显示最新版本的 tableview,它没有静态单元格。

我已经尝试删除 /Users/xxx/Library/Developer/Xcode/DerivedData 目录,清理构建文件夹,删除 iPhone 上的应用程序并再次运行,重新启动 iPhone。没有任何效果。

Storyboard version
What shows on device

代码如下:

import UIKit

class NewDebtViewController: 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


    let saveText = NSLocalizedString("Save", comment: "Save")

    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: saveText, style: .done, target: self, action: #selector(saveDebt))
}

//Function to go back
@objc func saveDebt(){

    //Here the code for saving the New Debt

    //print("Back Button Clicked")
    _ = navigationController?.popViewController(animated: true)
}

// 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.destination.
    // Pass the selected object to the new view controller.
}
*/

还有什么要检查或做什么?

Runtime Hierarchy

【问题讨论】:

  • 你的标签,tableview里面的textfield?
  • 其实它只是显示一个空的uitableview。
  • 您能否检查 tableView 和其他视图的层次结构并上传您的故事板的文档大纲?您可以在运行时使用调试视图层次结构进行检查
  • 层次结构实际上只显示表格分隔符。

标签: ios swift xcode uistoryboard


【解决方案1】:

解决了。虽然我在 Storyboard 中设计了类中的委托代码,但在逻辑上返回 0 的行数在 iPhone 中没有行:

这是为要解决的问题而注释的邪恶代码。 // MARK: - 表格视图数据源

override func numberOfSections(in 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 4
}

这是运行时的屏幕截图: iPhone Runtime

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 2015-10-26
    • 2019-06-13
    • 2018-08-17
    • 2020-08-21
    • 1970-01-01
    相关资源
    最近更新 更多