You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/platform_view_swift/ios/Runner/PlatformViewController.swift

38 lines
1.0 KiB

// Copyright 2018, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import UIKit
import Foundation
protocol PlatformViewControllerDelegate {
func didUpdateCounter(counter: Int)
}
class PlatformViewController : UIViewController {
var delegate: PlatformViewControllerDelegate? = nil
var counter: Int = 0
@IBOutlet weak var incrementLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
setIncrementLabelText()
}
func handleIncrement(_ sender: Any) {
self.counter += 1
self.setIncrementLabelText()
}
func switchToFlutterView(_ sender: Any) {
self.delegate?.didUpdateCounter(counter: self.counter)
dismiss(animated:false, completion:nil)
}
func setIncrementLabelText() {
let text = String(format: "Button tapped %d %@", self.counter, (self.counter == 1) ? "time" : "times")
self.incrementLabel.text = text;
}
}