【发布时间】:2017-03-20 21:36:08
【问题描述】:
我有 2 个视图控制器,ShipmentsOfResourcesVC 和 PopupVC。 ShipmentsOfResourcesVC 是主视图控制器,它是一个包含多个单元格的表格视图。当你按下一个单元格时,它应该会转到 PopupVC。
segue 工作正常,PopupVC 显示正确,但我遇到的问题是当 PopupVC 出现时,背景是透明的一秒钟然后变黑?我在下方提供了一个链接,指向 YouTube 上演示该问题的 15 秒短片。
在我第一次创建 segue 之前,这不是问题。 PopupVC 将以标准的白色背景出现。但是,我确实开始尝试更改 PopupVC 的背景,例如使其透明并摆弄模糊和活力效果,但我删除了所有这些代码,我仍然得到这个黑色背景。还要确保在 Storyboard 中检查视图的背景颜色设置为白色。我已经尝试删除 segue 并使用不同的名称创建一个新的。我删除了手机上的应用程序并重新安装它,这发生在我的设备和模拟器上。有任何想法吗?可能的错误?在 Xcode 8.2.1 中使用 Swift 3。
ShipmentsOfResourcesVC
import UIKit
class ShipmentsOfResourcesVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var myTableView: UITableView!
@IBOutlet weak var falloutCompanionLabel: UILabel!
var resourceList = ResourceList().listOfResources()
var numberOfResources = ResourceList().numberOfResources()
override func viewDidLoad() {
super.viewDidLoad()
myTableView.delegate = self
myTableView.dataSource = self
myTableView.backgroundImage()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? PopupVC {
destination.name = resourceList[myTableView.indexPathForSelectedRow!.row]
}
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return numberOfResources
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath)
let row = indexPath.row
cell.textLabel?.text = resourceList[row]
cell.textLabel!.textAlignment = .center
cell.textLabel!.textColor = UIColor.darkGray
return cell
}
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
}
PopupVC
import UIKit
class PopupVC: UIViewController {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var vendorLabel: UILabel!
@IBOutlet weak var locationLabel: UILabel!
@IBOutlet weak var quantityLabel: UILabel!
@IBOutlet weak var map: UIImageView!
@IBOutlet weak var popupView: UIView!
var name = ""
override func viewDidLoad() {
super.viewDidLoad()
popupView.layer.cornerRadius = 20
print("The name is \(name)")
nameLabel.text? = name
switch name {
case "Acid":
vendorLabel.text = "Vendor: Kay"
locationLabel.text = "Location: Bunker Hill"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Adhesive":
vendorLabel.text = "Vendor: Daisy"
locationLabel.text = "Location: Goodneighor"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Aluminum":
vendorLabel.text = "Vendor: Arturo"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 50"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Antiseptic":
vendorLabel.text = "Vendor: Doctor Sun"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Asbestos":
vendorLabel.text = "Vendor: Trashcan Carla"
locationLabel.text = "Location: Sanctuary Hills/Bunker Hill"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Ballistic Fiber":
vendorLabel.text = "Vendor: KLEO"
locationLabel.text = "Location: Goodneighor"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Ceramic":
vendorLabel.text = "Vendor: Myrna/Percy"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Circuitry":
vendorLabel.text = "Vendor: Daisy"
locationLabel.text = "Location: Goodneighor"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Cloth":
vendorLabel.text = "Vendor: Connie"
locationLabel.text = "Location: Abernathy Farm"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Concrete":
vendorLabel.text = "Vendor: Connie"
locationLabel.text = "Location: Abernathy Farm"
quantityLabel.text = "Quantity: 50"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Copper":
vendorLabel.text = "Vendor: Arturo"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Cork":
vendorLabel.text = "Vendor: Moe"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Crystal":
vendorLabel.text = "Vendor: Daisy"
locationLabel.text = "Location: Goodneighor"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Fertilizer":
vendorLabel.text = "Vendor: Connie"
locationLabel.text = "Location: Abernathy Farm"
quantityLabel.text = "Quantity: 50"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Fiber Optics":
vendorLabel.text = "Vendor: Proctor Teagan"
locationLabel.text = "Location: The Prydwen"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Fiberglass":
vendorLabel.text = "Vendor: Deb or Lucas"
locationLabel.text = "Location: Bunker Hill"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Gears":
vendorLabel.text = "Vendor: Arturo"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Glass":
vendorLabel.text = "Vendor: Doctor Sun"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 50"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Gold":
vendorLabel.text = "Vendor: Deb"
locationLabel.text = "Location: Bunker Hill"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Lead":
vendorLabel.text = "Vendor: KLEO"
locationLabel.text = "Location: Goodneighor"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Leather":
vendorLabel.text = "Vendor: Connie"
locationLabel.text = "Location: Abernathy Farm"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Nuclear Material":
vendorLabel.text = "Vendor: Alexis"
locationLabel.text = "Location: Vault 81"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Oil":
vendorLabel.text = "Vendor: KLEO"
locationLabel.text = "Location: Goodneighbor"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Plastic":
vendorLabel.text = "Vendor: Myrna/Percy"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Rubber":
vendorLabel.text = "Vendor: Doctor Sun"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Silver":
vendorLabel.text = "Vendor: Daisy"
locationLabel.text = "Location: Goodneighbor"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Springs":
vendorLabel.text = "Vendor: Myrna/Percy"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Screws":
vendorLabel.text = "Vendor: Arturo"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 25"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Steel":
vendorLabel.text = "Vendor: Myrna/Percy"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 100"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
case "Wood":
vendorLabel.text = "Vendor: Moe"
locationLabel.text = "Location: Diamond City"
quantityLabel.text = "Quantity: 100"
map.image = #imageLiteral(resourceName: "Goodneighbor.gif")
default:
print("That item doesn't exist.")
}
}
@IBAction func xButton(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
}
【问题讨论】: