在新的View Controller上加载内容

时间:2018-12-09 23:26:57

标签: ios swift

在我的主视图控制器中,我有一段代码,一旦相机识别出某些东西并且您点击屏幕,即可将您转到另一页:

@objc func screenTapped(_ sender:UITapGestureRecognizer){
    print ("go to page for \(identifierLabel.text)")
    if currentIdentifier == "Morel"{
        let newVc = MorelViewController()
        navigationController?.pushViewController(newVc, animated: 
true)
    }

在新的视图控制器中,我具有用于信息表视图的代码:

 struct CellData {
    let image: UIImage?
    let contentTitle: String?
    let content: String?
   } 

import UIKit

class MorelViewController: UITableViewController {

var nature = [CellData]()
var consumption = [CellData]()
var sensory = [CellData]()

override func viewDidLoad() {
    super.viewDidLoad()

    menuBar.tableView = tableView

    self.navigationItem.title = "Morel Mushroom"
    navigationController?.navigationBar.isTranslucent = false

    let titleLabel = UILabel()
    titleLabel.text = "Morel Mushroom"
    titleLabel.textColor = UIColor.white
    navigationItem.titleView = titleLabel

nature = [CellData.init(image: #imageLiteral(resourceName: "Asset 1"), 
contentTitle: "WHERE TO FIND", content: "You'll find edible morel in 
rich soil that's full of nutrients—in parks, gardens, and open 
deciduous forests. They can also pop up in cemeteries and ramparts, 
often where wood chips have been laid down. They're a relatively rare 
find, so keep an eye on the forest floor."), CellData.init(image: 
#imageLiteral(resourceName: "Asset 1-1"), contentTitle: "WHEN TO 
FIND", content: "Morels are one of the first great edible mushrooms of 
spring. They usually fruit in April and May, but can linger into 
June."), CellData.init(image: #imageLiteral(resourceName: "Asset 1- 
2"), contentTitle: "FORAGING GUIDELINES", content: "Only pick morels 
that have firm, springy flesh and nice, white stems. By the end of 
their season, morels tend to be infested with larvae, beetles, and 
other small creatures, but unwelcome guests may be hiding in their 
intricate surface and hollow interior regardless of when they’re 
picked. Be thorough, then, when brushing and washing them—but also be 
careful not to oversoak them as morels are extremely porous. Harvest 
the mushroom by carefully twisting it loose or cutting it at its base. 
Check the cut to see if the mushroom is infested with vermin and if 
the flesh is even.")] 

...

当对象被识别并即时切换到新的视图控制器时,在自然部分之后即时通讯会显示此错误:

 Thread 1: EXC_BREAKPOINT (code=1, subcode=0x102ffc304)

错误图片链接

Screen shot

我没有设置断点,这可能是什么问题?

1 个答案:

答案 0 :(得分:0)

我的猜测是这些名称之一是错误的:

image: #imageLiteral(resourceName: "Asset 1") // or one of the others

不再有图像文字,因此形成这些文字的唯一方法是手工操作,这可能导致不连贯的情况。我建议将它们全部替换为UIImage(named:),如下所示:

image: UIImage(named: "Asset 1") // and so on

如果名称错误,则可能会显示nil图片,但至少不会在该行崩溃。