Search code examples
iosswiftxcodesegueuistoryboardsegue

Two different buttons performing segue to same view controller but want to disable user interaction for segue through one button


I am performing segue to same view controller from two different buttons on same screen and hence using same segue identifier. Say buttons are B1 and B2. So when when I perform segue from segue from B1, I want destination view controller to have user interaction disabled but when when I segue from B2, I want destination view controller to to be clickable and its text fields to be editable. Please help me implement it. Here...consider B2 to be partialpressed and B1 to be toplbl and please help me implement it using this code so suggest me changes i can make here.

@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(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
    {
              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()
    }

}

override func prepareForSegue(segue: UIStoryboardSegue, sender: 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

    }

}

Solution

  • I found out an easy way to do it. We can declare one global or local boolean variable for partialpressed button we can set it to true and for toplbl button we can set it to false and then we have 2 ways to disable user interaction :

    1. if bool is global: go to destination view controller and inside view did load check for if bool == false then set self.view.userinteraction = false

    2. if bool is local variable: go to prpareforsegue inside initial view controller and check for if bool == false then set segue.destinationviewcontroller.view.userinteraction = false