我是Swift的新手,并且一直坚持这个问题。
我正在尝试添加“设置”视图,其中可以为主视图更新字体大小。
我在行上发现了Thread 1: signal SIGART
错误:class AppDelegate: UIResponder, UIApplicationDelegate
添加以下代码后,当我按下设置按钮时,我的应用程序现在崩溃了。
不确定如何调试此问题,任何帮助将不胜感激!提前谢谢。
查看控制器:
class ViewController: UIViewController, CLLocationManagerDelegate, SettingsViewControllerDelegate {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SettingsViewController" {
let settingsViewController = segue.destination as? SettingsViewController
if let viewController = settingsViewController {
viewController.delegate = self
}
}
}
func makeChangesToFont(size: Int) {
if (self.distanceReading.font.pointSize > 20) {
self.distanceReading.font = UIFont(name: self.distanceReading.font.fontName, size: CGFloat(size))
}
}
...
}
设置控制器:
import UIKit
protocol SettingsViewControllerDelegate {
func makeChangesToFont(size: Int)
}
class SettingsViewController: UIViewController {
var delegate: SettingsViewControllerDelegate?
@IBAction func IncreaseSize(_ sender: UIButton) {
print("something")
increaseFontSize()
}
func increaseFontSize() {
let mainView = parent as! ViewController
let text = mainView.distanceReading
let fontSize = (text?.font.pointSize)! + 10
print(fontSize)
if let delegate = self.delegate {
delegate.makeChangesToFont(size: Int(fontSize))
}
}
...
}
我在Xcode 8.2.1中使用Swift 3