简体   繁体   English

iosMath 正在崩溃 SwiftUI

[英]iosMath is crashing SwiftUI

I'm trying to build a Mac App using SwiftUI where I want to display Math using IosMath .我正在尝试使用 SwiftUI 构建一个 Mac 应用程序,我想在其中使用IosMath显示 Math 。 I installed it using CocoaPods and I'm able to import it.我使用 CocoaPods 安装它,我可以导入它。 But every Time I try to get to my View Containing the MTMathUILabel my App is crashing saying: 027055+0200 latextest[1709:84867] [General] -[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: latextest.Latex in bundle (null).但是每次我尝试进入包含 MTMathUILabel 的视图时,我的应用程序都会崩溃说: 027055+0200 latextest[1709:84867] [General] -[NSNib _initWithNibNamed:bundle:options:] could not load the nibName: latextest.Latex in bundle (null).

My code goes as following: In SwiftUI:我的代码如下: 在 SwiftUI 中:

import SwiftUI

struct Mittel: View {
    var body: some View {
        VStack{
            Text("Das Mittel berechnet sich: ")
            Switcher()
        }
    }

}

calling my NSViewControllerRepresentable:调用我的 NSViewControllerRepresentable:

import AppKit
import SwiftUI


struct Switcher : NSViewControllerRepresentable {
    func makeNSViewController(context: Context) -> Latex {
        print("Test")
        return Latex()
    }

    func updateNSViewController(_ nsViewController: Latex, context: Context) {
    
    }
}

to load the View:加载视图:

import AppKit
import iosMath

class Latex: NSViewController {

    //public var latexstring: String! = "\\frac{2}{3}"
    //let latexlabel = MTMathUILabel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let container1 = NSView(frame: CGRect(x: 0, y: 0, width: 200, height: 70))
        let label: MTMathUILabel = MTMathUILabel()
        label.latex = "x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}"

        label.frame = container1.frame
        container1.addSubview(label)
        self.view.addSubview(container1)
        }
}

Solution: There was no nib file because I wasn't using InterfaceBuilder... so I needed to change the Controller see解决方案:没有 nib 文件,因为我没有使用 InterfaceBuilder... 所以我需要更改 Controller 参见

    override func viewDidLoad() {
    super.viewDidLoad()

needed to be changed to.需要更改为。

override func loadView() {
self.view = NSView()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM