【发布时间】:2015-06-01 23:06:26
【问题描述】:
所以我有一个 2 屏幕应用程序,一个主 ViewController 和另一个 ViewController,它会在按下按钮时继续运行。这一切都很好,现在仍然可以。
然后我创建了一个新的 ViewController,向其中添加了一个 TableView,嵌入了一个导航控制器并设置了我的表格。我为它创建了一个 segue,这是通过按下 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()
}
}
感谢您的帮助!
【问题讨论】:
标签: ios uitableview swift uiviewcontroller tableview