gpt4 book ai didi

ios - 如何在 iOS 中的 prepareForSegue 之前执行按钮按下操作?

转载 作者:搜寻专家 更新时间:2023-11-01 07:29:36 24 4
gpt4 key购买 nike

我正在创建一个 iOS 应用程序,我想在运行 prepareForSegue 方法之前在按下按钮时执行分配操作。

我使用主 Storyboard创建了所有控件。

一些按钮的执行顺序是按钮按下 Action -> prepareForSegue

但对于某些按钮来说是prepareForSegue-> 按钮按下 Action

如何更改第二组按钮的顺序?

这是我使用的代码:

import UIKit

class SummaryViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

var button_prsd = "none"

@IBAction func people_insights(sender: AnyObject) {
button_prsd = "people_insights"
}

@IBAction func industry_research(sender: AnyObject) {
button_prsd = "industry_research"
}

@IBAction func holidays_events(sender: AnyObject) {
button_prsd = "holidays_events"
}

@IBAction func monthly_spotlights(sender: AnyObject) {
button_prsd = "monthly_spotlights"
}

@IBAction func blog(sender: AnyObject) {
button_prsd = "blog"
}


@IBAction func about_us(sender: AnyObject) {
button_prsd = "about_us"
print("button press about us executed")
}


@IBAction func settings(sender: AnyObject) {
button_prsd="settings"
print("button press settings executed")

}


@IBAction func quiz(sender: AnyObject) {
button_prsd="quiz"
print("button press quiz executed")
}

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.

let next_view = segue.destinationViewController

if(next_view is DetailViewController)
{
let det_view = next_view as! DetailViewController
det_view.link = button_prsd
print("segue executed")
} else if(next_view is DetailTableViewController)
{
let det_view = next_view as! DetailTableViewController

print("segue executed")
}
}
}

最佳答案

我弄清楚了问题,当以这种方式给出然后代码时,执行只是按字母顺序,所有其他方法都在 prepareForSegue 之前执行,因为这些方法按字母顺序排在上面

当我将测验和设置方法重命名为 a_quiz 和 a_settings 时,它起作用了

关于ios - 如何在 iOS 中的 prepareForSegue 之前执行按钮按下操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33466275/

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