Reputation: 284
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
}
}
Upvotes: 0
Views: 970
Reputation: 1479
You could also use an Int, like so:
var buttonIndex = 0
@IBAction func partialPressed(sender: UIButton){
buttonIndex = 1
performSegueWithIdentifier("PartialPopup", sender: sender)
}
@IBAction func toplbl(sender: UIButton){
buttonIndex = 2
performSegueWithIdentifier("PartialPopup", sender: sender)
}
Then:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
destVC == segue.destination
destVC.buttonIndex = self.buttonIndex
}
And then, in destVC:
var buttonIndex = 0
switch buttonIndex{
case 1:
// Do whatever magic is desired if partialPressed was tapped
case 2:
// Do whatever magic is desired if toplbl was tapped
default:
break
}
Upvotes: 0
Reputation: 284
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 :
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
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
Upvotes: 0
Reputation: 86
You can use one key, and change the value of that key before calling segue. And according to that key change the interaction of buttons/textfields etc. This is a workaround, maybe you will get better answer than this.
Upvotes: 0
Reputation: 726479
Use prepareForSegue:
method. iOS will pass you the button as a sender
parameter, and also make the destination view controller available as part of UIStoryboardSegue
parameter.
Check sender
to see if it is B1
or B2
. When the sender is B2
, disable user interaction in segue's destination controller:
override func prepareForSegue(segue: UIStoryboardSegue!, sender: Any?) {
if segue.identifier == "MySegue" {
let enableInteration = (sender != button2)
segue.destinationViewController.view.userInteractionEnabled = enableInteration
}
}
Upvotes: 1