간단한 앱이 있습니다. 앱에 대한 정보가 들어있는 Info라는 View Controller를로드하는 버튼이 있습니다. Info View Controller에는 "View Back"버튼이있어서 사용자는 다시 View Controller로 이동합니다. 메인 화면에는 int가 들어있는 countLabel라는 레이블이 있으며, 정보 화면으로 돌아가서 Int의 값을 기본값으로 되돌립니다. 다른 화면에서 Int의 값을 유지하려면 어떻게해야합니까?다른보기 컨트롤러를 볼 때 레이블 텍스트 저장
// ViewController.swift
// Simple Count
//
// Created by Jamie King on 11/19/17.
// Copyright © 2017 Jamie King. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var countValue = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBOutlet weak var countLabel: UILabel!
@IBAction func countButton(_ sender: Any) {
countValue = countValue + 1;
update()
}
@IBAction func minusButton(_ sender: Any) {
countValue = countValue - 1
update()
}
@IBAction func resetButton(_ sender: Any) {
countValue = 0
update()
}
@IBAction func infoButton(_ sender: Any) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func update(){
countLabel.text = "\(countValue)"
}
}
것은''countValue' – Torongo
추가 self.countValue의 self.countValue'instead를 사용해보십시오 그러나 이것은 서로 반환 값을 유지하지 않는 것 컨트롤러보기. – Zakth
'update()'func에 추가 했습니까? 'countLabel.text = "\ (self.countValue)"' – Torongo