약관보기는 내 앱에 & 상태로 구현 중이며 사용자는이를 수락해야만 진행할 수 있습니다. 그러면 수락 할 때 더 이상 약관을 검토하지 않아도됩니다. & 조건보기. UserDefaults
을 통합하고 누군가가 약관에 동의하면 값을 로컬에 저장하는 방법에 대한 자습서를 따랐습니다. 그러나 나는 그것을 루트보기 컨트롤러에 구현하는 붙어있다. 특히 내 viewDidAppear
기능에 붙어 있습니다. if 및 else 문은 무엇이 들어 있습니까?처음 출시시에만보기 - 스위프트 3
0
A
답변
2
은 아마, 당신은 "처음 시작 만에게에 의 ViewController보기"를 의미
class TermsAndConditionsViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var termsTextView: UITextView! {
didSet {
termsTextView.delegate = self
}
}
@IBOutlet weak var acceptButton: UIButton! {
didSet {
acceptButton.isHidden = true
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
acceptButton.isHidden = scrollView.contentOffset.y + scrollView.bounds.height < scrollView.contentSize.height
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if UserDefaults.standard.bool(forKey: "termsAccepted") {
} else {
}
}
@IBAction func acceptButtonTapped(_ sender: Any) {
performSegue(withIdentifier: "toPeekView", sender: sender)
}
}. 이 목적을 위해 UserDefaults를 사용
용어가 하지이 TermsAndConditionsViewController
계층에 있어야 인정하는 경우 대신, 그것은 AppDelegate에에 있어야합니다, 확인하지만, 좋은 생각 - application:didFinishLaunchingWithOptions
을, 당신은 루트의 ViewController 여부에 결정할 수 있습니다 TermsAndConditionsViewController
또는 다른 ViewController (예 : HomeViewController) 여야합니다.
AppDelegate에 :
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootViewController = storyboard.instantiateViewController(withIdentifier: UserDefaults.standard.bool(forKey: "termsAccepted") ? "termsViewControllerID" : "homeViewControllerID")
window?.rootViewController = rootViewController
return true
}
TermsAndConditionsViewController이 도움이
class TermsAndConditionsViewController: UIViewController {
//...
@IBAction func acceptButtonTapped(_ sender: Any) {
UserDefaults.standard.set(true, forKey: "termsAccepted")
performSegue(withIdentifier: "toPeekView", sender: sender)
}
//...
}
희망.
가능한 복제본 [처음 시작했을 때보기 만 표시하려면 어떻게합니까?] (http://stackoverflow.com/questions/12878162/how-can-i-show-a-view-on-the-first) -launch-only) – JAL
뷰가 첫 번째 ViewController에 나타나야합니까? 또는 그것은 분리 된 ViewController입니까? –
루트보기 컨트롤러에 나타나야합니다. 그러면 조건이 받아 들여지면 확인되어 다음보기 컨트롤러를 새 루트보기 컨트롤러로 만듭니다 – Gar