私は簡単なファクトアプリを作成しています(迅速に)。すべてのファクトは別々のビューコントローラーにあり、ユーザーがアプリを閉じると、すべてメインページに移動し、ファクト1からやり直す必要があります。
ユーザーが閉じたときに使用していたビューコントローラーを保存する方法を知りたいのですが、ユーザーがファクトを再度確認すると、そのファクトから開始されます。ありがとう:)また誰かがビデオを作った場合、私はそれがYTチャンネルを始めるのに十分なビューを得ると思います
Swift5に更新
あなたはUserDefaults
あなたの最後を覚えているだろうを使うことができますViewController
。
まず、以下に示すようなビューをロードするときに、整数を格納する必要があります。
FirstView.swift
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.setValue(0, forKey: "View")
// Do any additional setup after loading the view, typically from a nib.
}
SecondViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.setValue(1, forKey: "View")
// Do any additional setup after loading the view.
}
次に、AppDelegate.swiftで、保存されている値を読み取り、その整数に関連するViewControllerを次のようにロードします。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let viewCount = UserDefaults.standard.integer(forKey: "View")
var VC = UIViewController()
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
println(viewCount)
if viewCount == 0 {
//FirstView should initiate
VC = storyboard.instantiateViewController(withIdentifier: "First") as! ViewController
} else if viewCount == 1 {
//SecondView should inititate
VC = storyboard.instantiateViewController(withIdentifier: "Second") as! SecondViewController
} else {
//ThirdView Should Initiate
VC = storyboard.instantiateViewController(withIdentifier: "Third") as! ThirdViewController
}
self.window?.makeKeyAndVisible()
self.window?.rootViewController = VC
return true
}
詳細については、このサンプルプロジェクトを確認してください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加