gpt4 book ai didi

ios - 当我切换到 Xcode 8 中的新 View Controller 时获得黑色背景?

转载 作者:行者123 更新时间:2023-11-28 08:14:29 25 4
gpt4 key购买 nike

我有 2 个 View Controller ,ShipmentsOfResourcesVC 和 PopupVC。 ShipmentsOfResourcesVC 是主视图 Controller ,它是一个包含多个单元格的 TableView 。当您按下一个单元格时,它应该转到 PopupVC。

segue 工作正常并且 PopupVC 正确显示,但我遇到的问题是当 PopupVC 出现时,背景透明一秒钟然后变黑?我在下方提供了一个链接,指向 YouTube 上演示该问题的 15 秒短片。

Video

在我第一次创建 segue 之前,这不是问题。 PopupVC 将以其标准的白色背景出现。然而,我确实开始尝试更改 PopupVC 的背景,例如使其透明并摆弄模糊和活力效果,但我删除了所有这些代码,但我仍然得到这个黑色背景。还要确保在 Storyboard 中检查 View 的背景颜色是否设置为白色。我试过删除 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)

}
}

弹出VC

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)
}
}

最佳答案

检查 PopupVC 上的背景颜色。它可能是透明的或黑色的。如果您希望它清晰并显示其背后的现有 View Controller ,那么您需要将呈现样式更改为“在当前上下文中”。

How to present a modal atop the current view in Swift

关于ios - 当我切换到 Xcode 8 中的新 View Controller 时获得黑色背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42914396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com