2016-10-13 53 views
0

我有一個窗體,用來自核心數據對象的值進行初始化。窗體上有一個按鈕,其中的圖像會轉到另一個視圖控制器,在其中可以選取其他圖片以設置爲圖像。選擇圖像後,視圖會回到表單,但之前加載的信息已重置。Swift - 如何停止從另一個segue返回後的重置

表單代碼:

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.gender.dataSource = self; 
    self.gender.delegate = self; 

    profilePic.setImage(UIImage(named: imgArray[row])!, forState: UIControlState.Normal); 
    fName.text = friend.firstName!; 
    lName.text = friend.lastName!; 
    mobile.text = friend.mobile!; 
    address.text = friend.address!; 
    if (friend.gender == "Male") 
    { 
     gender.selectRow(0, inComponent: 0, animated: true); 
    } 
    else 
    { 
     gender.selectRow(1, inComponent: 0, animated: true); 
    } 
} 

按鈕,單擊代碼:

@IBAction func profilePicClick(sender: AnyObject) { 
    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("picList") as! PicListTableViewController 
    nextViewController.viewCaller = "edit"; 
    self.presentViewController(nextViewController, animated: true, completion: nil) 
} 

圖片列表返回代碼:

if (viewCaller == "edit") 
{ 
    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("editFriend") as! EditFriendViewController 
    nextViewController.row = indexPath.row; 
    nextViewController.n = 1; 
    self.presentViewController(nextViewController, animated: true, completion: nil) 
} 

一切功能正常的只選擇回國後的表格休息圖片。

回答

2

看起來好像你不回到以前的視圖控制器,而是提出一個新的視圖控制器。試試這在你的返回方法:

dismiss(animated: true, completion: nil) 

除此之外,你應該傳遞一個選定的圖像回你原來的視圖控制器。你可以通過使用委託模式(在模態視圖控制器上選擇圖像後立即調用委託方法)來實現此目的。

相關問題