mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Add platform_view_swift based on platform_view example (#10)
This commit is contained in:
committed by
Andrew Brogdon
parent
370a72caa5
commit
c02d0208fa
37
platform_view_swift/ios/Runner/PlatformViewController.swift
Normal file
37
platform_view_swift/ios/Runner/PlatformViewController.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user