0

В одной библиотеке наткнулся на View Controller, который задаётся исключительно с помощью кода, то есть, Storyboard там нет. Но мне нужно настроить переходы от одного View Controller к другому и так далее. И вот как настраивать такой VC?

Прилагаю код (с помощью него строится график):

import UIKit
import QuartzCore

class MainViewController: UIViewController, LineChartDelegate {



var label = UILabel()
var lineChart: LineChart!



override func viewDidLoad() {
    super.viewDidLoad()

    var views: [String: AnyObject] = [:]

    label.text = "..."
    label.translatesAutoresizingMaskIntoConstraints = false
    label.textAlignment = NSTextAlignment.center
    self.view.addSubview(label)
    views["label"] = label


view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[label]-|", options: [], metrics: nil, views: views))
    view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-80-[label]", options: [], metrics: nil, views: views))

    // simple arrays
    let data: [CGFloat] = [3, 4, -2, 11, 13, 15]
    let data2: [CGFloat] = [1, 3, 5, 13, 17, 20]

    // simple line with custom x axis labels
    let xLabels: [String] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]

    lineChart = LineChart()
    lineChart.animation.enabled = true
    lineChart.area = true
    lineChart.x.labels.visible = true
    lineChart.x.grid.count = 1
    lineChart.y.grid.count = 1
    lineChart.x.labels.values = xLabels
    lineChart.y.labels.visible = true
    lineChart.addLine(data)
    lineChart.addLine(data2)

    lineChart.translatesAutoresizingMaskIntoConstraints = false
    lineChart.delegate = self
    self.view.addSubview(lineChart)
    views["chart"] = lineChart
    view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-[chart]-|", options: [], metrics: nil, views: views))
    view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[label]-[chart(==200)]", options: [], metrics: nil, views: views))



override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}



/**
 * Line chart delegate method.
 */
func didSelectDataPoint(_ x: CGFloat, yValues: Array<CGFloat>) {
    label.text = "x: \(x)     y: \(yValues)"
}



/**
 * Redraw chart on device rotation.
 */
override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
    if let chart = lineChart {
        chart.setNeedsDisplay()
    }
  }

}

1 ответ 1

1

Я так понимаю, вы хотите перейти на этот самый MainViewController с другого VC.

let mainViewController = MainViewController()
self.navigationController?.pushViewController(mainViewController, animated: true)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.