gpt4 book ai didi

ios - 两个不同的按钮对同一 View Controller 执行 segue,但希望通过一个按钮禁用 segue 的用户交互

转载 作者:行者123 更新时间:2023-11-28 16:11:07 25 4
gpt4 key购买 nike

我正在从同一屏幕上的两个不同按钮对同一 View Controller 执行 segue,因此使用相同的 segue 标识符。假设按钮是 B1 和 B2。因此,当我从 B1 的 segue 执行 segue 时,我希望目标 View Controller 禁用用户交互,但是当我从 B2 的 segue 执行时,我希望目标 View Controller 可单击且其文本字段可编辑。请帮我实现它。这里...考虑将 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 参数传递给您,并使目标 View Controller 作为 UIStoryboardSegue 参数的一部分可用。

检查sender,看它是B1还是B2。当发送者为 B2 时,在 segue 的目标 Controller 中禁用用户交互:

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

关于ios - 两个不同的按钮对同一 View Controller 执行 segue,但希望通过一个按钮禁用 segue 的用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39544629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com