两个不同的按钮对同一视图控制器执行 segue,但希望通过一个按钮禁用 segue 的用户交互
Two different buttons performing segue to same view controller but want to disable user interaction for segue through one button
我正在从同一屏幕上的两个不同按钮对同一视图控制器执行 segue,因此使用相同的 segue 标识符。假设按钮是 B1 和 B2。因此,当我从 B1 的 segue 执行 segue 时,我希望目标视图控制器禁用用户交互,但是当我从 B2 的 segue 执行时,我希望目标视图控制器可单击且其文本字段可编辑。请帮我实现它。这里...考虑将 B2 部分按下,将 B1 考虑为 toplbl,请帮助我使用此代码实现它,以便建议我可以在此处进行更改。
@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()
}
}
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
}
}
使用prepareForSegue:
方法。 iOS 会将按钮作为 sender
参数传递给您,并使目标视图控制器作为 UIStoryboardSegue
参数的一部分可用。
检查 sender
以查看它是 B1
还是 B2
。当发件人是 B2
时,在 segue 的目标控制器中禁用用户交互:
override func prepareForSegue(segue: UIStoryboardSegue!, sender: Any?) {
if segue.identifier == "MySegue" {
let enableInteration = (sender != button2)
segue.destinationViewController.view.userInteractionEnabled = enableInteration
}
}
您可以使用一个键,并在调用 segue 之前更改该键的值。并根据该键更改 buttons/textfields 等的交互。这是一种解决方法,也许您会得到比这更好的答案。
我找到了一个简单的方法。我们可以为 partialpressed 按钮声明一个全局或局部布尔变量,我们可以将其设置为 true,对于 toplbl 按钮,我们可以将其设置为 false,然后我们有 2 种方法来禁用用户交互:
如果 bool 是全局的:转到目标视图控制器并且内部视图确实加载检查是否 bool == false 然后设置 self.view.userinteraction = false
如果 bool 是局部变量:转到初始视图控制器内的 prpareforsegue 并检查是否 bool == false 然后设置 segue.destinationviewcontroller.view.userinteraction = false
你也可以使用 Int,像这样:
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)
}
然后:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
destVC == segue.destination
destVC.buttonIndex = self.buttonIndex
}
然后,在 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
}
我正在从同一屏幕上的两个不同按钮对同一视图控制器执行 segue,因此使用相同的 segue 标识符。假设按钮是 B1 和 B2。因此,当我从 B1 的 segue 执行 segue 时,我希望目标视图控制器禁用用户交互,但是当我从 B2 的 segue 执行时,我希望目标视图控制器可单击且其文本字段可编辑。请帮我实现它。这里...考虑将 B2 部分按下,将 B1 考虑为 toplbl,请帮助我使用此代码实现它,以便建议我可以在此处进行更改。
@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()
}
}
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
}
}
使用prepareForSegue:
方法。 iOS 会将按钮作为 sender
参数传递给您,并使目标视图控制器作为 UIStoryboardSegue
参数的一部分可用。
检查 sender
以查看它是 B1
还是 B2
。当发件人是 B2
时,在 segue 的目标控制器中禁用用户交互:
override func prepareForSegue(segue: UIStoryboardSegue!, sender: Any?) {
if segue.identifier == "MySegue" {
let enableInteration = (sender != button2)
segue.destinationViewController.view.userInteractionEnabled = enableInteration
}
}
您可以使用一个键,并在调用 segue 之前更改该键的值。并根据该键更改 buttons/textfields 等的交互。这是一种解决方法,也许您会得到比这更好的答案。
我找到了一个简单的方法。我们可以为 partialpressed 按钮声明一个全局或局部布尔变量,我们可以将其设置为 true,对于 toplbl 按钮,我们可以将其设置为 false,然后我们有 2 种方法来禁用用户交互:
如果 bool 是全局的:转到目标视图控制器并且内部视图确实加载检查是否 bool == false 然后设置 self.view.userinteraction = false
如果 bool 是局部变量:转到初始视图控制器内的 prpareforsegue 并检查是否 bool == false 然后设置 segue.destinationviewcontroller.view.userinteraction = false
你也可以使用 Int,像这样:
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)
}
然后:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
destVC == segue.destination
destVC.buttonIndex = self.buttonIndex
}
然后,在 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
}