2016-09-17 53 views
0

我從同一屏幕上的兩個不同按鈕執行segue到相同的視圖控制器,因此使用相同的segue標識符。說按鈕是B1和B2。所以當我從B1從segue執行segue時,我希望目標視圖控制器禁用用戶交互,但是當我從B2中繼續時,我希望目標視圖控制器可以點擊並且其文本字段可以編輯。請幫我實施它。在這裏...考慮B2是部分壓力,B1是toplbl,請幫助我使用此代碼實施它,所以建議我可以在這裏修改。兩個不同的按鈕執行segue到相同的視圖控制器,但希望通過一個按鈕禁用segue的用戶交互

@IBAction func partialPressed(sender: UIButton) 
{ 
    let i = self.getIndex(sender.tag) 
    let j = self.getSection(sender.tag) 
    let indexarr = ["index":i, "section":j] 

    if getSection(sender.tag) == 0 
    { 

    let arr = getArray(sender.tag) 
    performSegueWithIdentifier("partialSupplement", sender: arr) 

    } 
    else if getSection(sender.tag) == 1 
    { 
     let arr = getArray(sender.tag) 
     performSegueWithIdentifier("PartialPopup", sender: arr) 




    } 

    else if getSection(sender.tag) == 2 
    { 
     let arr = getArray(sender.tag) 
     performSegueWithIdentifier("FoodLifestyle", sender: arr) 



    else if getSection(sender.tag) == 3 
    { 
     let arr = getArray(sender.tag) 
     performSegueWithIdentifier("Food", sender: arr) 


    else if getSection(sender.tag) == 4 
    { 
     let arr = getArray(sender.tag) 
     performSegueWithIdentifier("Others", sender: arr) 
     task.resume() 
    } 

} 

@IBAction FUNC toplbl(發件人:的UIButton){

let i = self.getIndex(sender.tag) 
    let j = self.getSection(sender.tag) 
    let indexarr = ["index":i, "section":j] 

    if getSection(sender.tag) == 0 
    { 
       task.resume() 

     let arr1 = getArray(sender.tag) 
     performSegueWithIdentifier("partialSupplement", sender: arr1) 





    } 
    else if getSection(sender.tag) == 1 
    { 
     let arr1 = getArray(sender.tag) 
     performSegueWithIdentifier("PartialPopup", sender: arr1) 


    } 

    else if getSection(sender.tag) == 2 
    { 
     let arr1 = getArray(sender.tag) 
     performSegueWithIdentifier("FoodLifestyle", sender: arr1) 

       task.resume() 
    } 

    else if getSection(sender.tag) == 3 
    { 
     let arr1 = getArray(sender.tag) 
     performSegueWithIdentifier("Food", sender: arr1) 
      task.resume() 
    } 

    else if getSection(sender.tag) == 4 
    { 
     let arr1 = getArray(sender.tag) 
     performSegueWithIdentifier("Others", sender: arr1) 
       task.resume() 
    } 

} 

倍率FUNC prepareForSegue(SEGUE:UIStoryboardSegue,發件人:AnyObject){

if segue.identifier == "menuviewcontroller" 
    { 
     let menuTableViewController = segue.destinationViewController as! MenuViewcontroller 
     menuTableViewController.transitioningDelegate = menuTransitionManager 
     menuTransitionManager.delegate = self 

     // menuTableViewController.customchildcelldataarray = self.customchildcelldataarray 

    } 
    if segue.identifier == "PartialPopup" 
    { 
     let popupViewController = segue.destinationViewController as! PatialViewController 
     popupViewController.arr = sender as! CustomcomingupDataWorkOut 
     //popupViewController.timings_id = popupViewController.arr.timings_id 
     //menuTransitionManager.delegate = self 
     // menuTableViewController.customchildcelldataarray = self.customchildcelldataarray 

    } 
    if segue.identifier == "partialSupplement" 
    { 
     let popupViewController = segue.destinationViewController as! PartialSupplementViewController 
     var arr = sender as! CustomcomingUpDataSupplements 
     popupViewController.lifestyletype = arr.supplementName 
     popupViewController.lifestyleItem = arr.amount + arr.unit 
     popupViewController.lifestyleQuantity = arr.dosage_main_name 
     popupViewController.timings_id = arr.timings_id 



     //popupViewController.arr = sender as! CustomcomingUpDataSupplements 
     //popupViewController.timings_id = popupViewController.arr.timings_id 
     //menuTransitionManager.delegate = self 
     // menuTableViewController.customchildcelldataarray = self.customchildcelldataarray 

    } 

    if segue.identifier == "FoodLifestyle" 
    { 
     let popupViewController = segue.destinationViewController as! partialFoodViewController 
     var arr = sender as! CustomcomingUpDataLifeStyle 
     popupViewController.lifestyletype = arr.lifestyle_name 
     popupViewController.lifestyleItem = arr.time + " minutes" 
     popupViewController.lifestyleQuantity = "Time" 
     popupViewController.timings_id = arr.timings_id 


     //popupViewController.arr = sender as! CustomcomingupDataWorkOut 
     //menuTransitionManager.delegate = self 
     // menuTableViewController.customchildcelldataarray = self.customchildcelldataarray 

    } 
    if segue.identifier == "Food" 
    { 
     let popupViewController1 = segue.destinationViewController as! FoodViewController 
     var arr = sender as! CustomcominUpDataFood 
     print(arr) 
     popupViewController1.type = arr.food_name 
     popupViewController1.Item = arr.time 
     popupViewController1.Quantity = " Amount" 
     popupViewController1.timings_id = arr.timings_id 


     //popupViewController.arr = sender as! CustomcomingupDataWorkOut 
     //menuTransitionManager.delegate = self 
     // menuTableViewController.customchildcelldataarray = self.customchildcelldataarray 

    } 
    //Others 
    if segue.identifier == "Others" 
    { 
     let popupViewController = segue.destinationViewController as! PartialOthersViewController 
     var arr = sender as! CustomcominUpDataOthers 
     popupViewController.lifestyletype = arr.others_name 
     popupViewController.lifestyleItem = arr.time + " minutes" 
     popupViewController.lifestyleQuantity = "Completion" 
     popupViewController.timings_id = arr.timings_id 
     //popupViewController.arr = sender as! CustomcomingupDataWorkOut 
     //menuTransitionManager.delegate = self 
     // menuTableViewController.customchildcelldataarray = self.customchildcelldataarray 

    } 

} 
+0

在'prepareForSegue'中檢查發件人,並在目標視圖控制器 – Paulw11

+0

@ Paulw11上設置一個屬性..可以給我完整的函數嗎?是否需要傳遞額外的對象? – Rouny

回答

0

我發現了一個簡單的方法來做到這一點。我們可以申報partialpressed按鈕一個全局或局部布爾變量,我們可以把它設置爲true和toplbl按鈕,我們可以將其設置爲false,然後我們有2種方法可以禁止用戶交互:

  1. 如果布爾是全球性的:去目的地視圖控制器和內部視圖做加載檢查,如果bool == false,然後設置self.view.userinteraction = false

  2. 如果bool是局部變量:轉到prpareforsegue內初始視圖控制器,並檢查是否布爾== false然後設置segue.destinationviewcontroller.view.userinteraction = false

1

prepareForSegue:使用方法。 iOS會將該按鈕作爲sender參數傳遞給您,還會使目標視圖控制器成爲UIStoryboardSegue參數的一部分。

檢查sender看看它是否是B1B2。當發送方爲B2,禁止用戶交互賽格瑞的目標控制器:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: Any?) { 
    if segue.identifier == "MySegue" { 
     let enableInteration = (sender != button2) 
     segue.destinationViewController.view.userInteractionEnabled = enableInteration 
    } 
} 
+0

你正在檢查這裏面的目標視圖控制器或初始視圖控制器,即從視圖控制器你在哪裏執行segue? – Rouny

+0

@Rouny這發生在「從」控制器。 – dasblinkenlight

+0

你可以建議我改變是我的代碼....我已貼在後的代碼。 – Rouny

0

您可以使用一個密鑰,並呼籲賽格瑞之前更改鍵的值。並根據該鍵改變按鈕/文本框等的交互。這是一個解決方法,也許你會得到比這更好的答案。

相關問題