2017-07-29 48 views
0

我正在做一个任务应用程序,您可以在其中提供日期/位置提醒。我想知道是否有无论如何暂时保存图片中的字段中的数据,当打开mapView选择地址或我必须将这些字段传递给mapView,然后回到addTaskVC时重新设置它们?临时打开新的ViewController时保存值

values I want to keep

+1

有一些方法可以通过使用'segue'在'ViewController'中传递参数(覆盖'prepare()'),但我建议使用'gateway''类的'全局变量'或'静态'成员。 –

+0

请说明你的流程,从你在哪里显示Mapview,它是在当前的导航。层次? , –

+0

当您按位置提醒我时,有一个按钮可以显示mapVC,所以是它位于当前导航层次结构中 –

回答

0

我使用的全局stuct救我的临时变量,然后他们装在里面viewDidLoad中或在需要加载

全球结构

struct tempVariablees { 

    static var taskTextField = "" 
    static var dateField = "" 
    static var dateSelected = false 

} 

那里ViewDidLoad

if tempVariablees.taskTextField != "" { 
     taskText.text = tempVariablees.taskTextField 
    } 
    if tempVariablees.dateField != "" && tempVariablees.dateSelected{ 
     dateSelected.text = tempVariablees.dateField 
     remindMeOnDay.isOn = true 
     userPickedDate = tempVariablees.dateSelected 
    }