簡體   English   中英

快速選擇到UITableViewController時黑屏

[英]Black screen when segueing to UITableViewController in swift

因此,我有一個可以正常工作的2屏幕應用程序,一個主ViewController和另一個ViewController,可以在按下按鈕時進行選擇。 一切正常,並且仍然可以。

然后,我創建了一個新的ViewController,向其中添加了TableView,嵌入了Navigation控制器並設置了我的表。 我為此創建了序列,方法是按下textField。 一切正常,但是偶爾應該連接到TableView VC時,它只是顯示黑屏。 沒有錯誤的報告,屏幕只是黑色,它永遠不會改變。 有時候,這一切都很好。 我以某種方式更改了表格后,它似乎出現了。 更令人煩惱的是,當它在模擬器上運行時,如果我隨后嘗試在我的設備(iPhone 6)上運行該構建,則在發生segue時仍然出現黑屏。 我真的不知道什么代碼對您有用,所以請問您是否想看一下。 我將代碼多數民眾贊成在tableView的VC上。

import UIKit

class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationBarDelegate {

@IBOutlet private weak var tableView: UITableView!

var countryPicker = ["Colombia", "England", "France", "Germany", "Brazil", "Austria", "Spain", "Australia", "USA", "Berlin", "Thailand", "Northern Ireland", "New Zealand", "Hawaii", "Switzerland", "Sweeden", "Finland", "Turkey", "Russia", "Netherlands", "Japan"]


override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.rowHeight = 50
    self.tableView.backgroundView = UIImageView(image: UIImage(named: "TblBackground"))

}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return countryPicker.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell

    if (indexPath.row % 2 == 0) {

        cell.backgroundColor = UIColor.clearColor()

    } else {

        cell.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.2)

        cell.textLabel?.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.0)

    }

    var imageView: UIImage! = UIImage(named: "Australia")
    cell.imageView?.image = imageView
    cell.imageView?.highlightedImage = UIImage(named: "Australia1")

    cell.textLabel?.text = countryPicker[indexPath.row]

    cell.textLabel?.textColor = UIColor.whiteColor()

    return cell
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    var cell = tableView.cellForRowAtIndexPath(indexPath)
    cell!.accessoryType = UITableViewCellAccessoryType.Checkmark
    cell?.textLabel!.textColor = UIColor.blueColor()

}

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

    var cell = tableView.cellForRowAtIndexPath(indexPath)
    cell!.accessoryType = UITableViewCellAccessoryType.None
    cell?.textLabel!.textColor = UIColor.whiteColor()

}

} 

謝謝你的幫助!

仍然沒有邏輯上的原因可以解釋為什么發生這種情況-但是完全清理構建文件夾已阻止了這種情況的發生。 因此,如果您遇到相同的問題,請嘗試以下操作:

  1. 使用Xcode時,轉到頂部欄,然后選擇“產品”
  2. 當列表出現時,您會看到“清潔”選項。
  3. 按住Alt鍵,該選項將更改為“清理構建文件夾”
  4. 點擊“清理構建文件夾”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM