我正在创建一个 iOS 应用程序,在运行方法prepareForSegue 之前,我想在按下按钮时执行分配操作。
我使用主要故事板创建了所有控件。
某些按钮的执行顺序是
按钮按下动作->prepareForSegue
但对于某些按钮来说是
准备ForSegue->按钮按下动作
如何更改第二组按钮的顺序?
这是我正在使用的代码:
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 时,它起作用了
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)