问题描述
我正在创建一个iOS应用程序,在其中我要在运行方法prepareForSegue之前通过按下按钮来执行分配操作.
I am creating an iOS application in which I want to perform an assignment action in button press before running the method prepareForSegue.
我使用主故事板创建了所有控件.
I created all controls using Main Story board.
某些按钮的执行顺序为按钮操作-> prepareForSegue
The order of execution for some buttons isbutton press action -> prepareForSegue
但是对于某些按钮是prepareForSegue->按钮按下动作
but for some buttons it isprepareForSegue-> button press action
如何更改第二组按钮的顺序?
How to change the order for second set of buttons?
这是我正在使用的代码:
Here is the code I am using:
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之前执行,因为这些方法按字母顺序排在上面
I figured out the problem, when give then code in this way, the execution is just alphabetical order, all the other methods were getting executed before prepareForSegue because the methods come above in alphabetical order
当我将测验和设置方法重命名为a_quiz和a_settings时,它起作用了
When I renamed the quiz and settings methods as a_quiz and a_settings, it worked
这篇关于如何在iOS中的prepareForSegue之前执行按钮按下操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!