gpt4 book ai didi

swift - 通过按钮链接 View Controller

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

我是所有这方面的初学者...话虽如此,我在我的应用程序中遇到了一个问题,我已经停滞不前,不知道下一步该做什么或修复。所以任何答案将不胜感激!

所以在我的主视图 Controller 中,我有四个按钮,它们具有四个不同的类别。这些类别中的每一个都有自己的问题列表,但它们有一个共同的“一般问题”列表。一般问题列表有自己的 View Controller 。当您单击四个按钮中的任何一个时,它会将您带到“一般问题” View 。在此 View 的底部,我有一个“下一步”按钮。

目标:根据 Home View Controller 中最初按下的内容,配置“下一步”按钮以继续到该类别的问题列表之一。

我已经通过 View Controller 中的 outlet 和 action 连接了按钮。但是,当我控制并拖动到 View Controller 中时,下一步按钮将不会连接。我不确定我需要将代码放在哪里...

我在想 Next 按钮的代码可能需要某种条件语句,但由于它不会连接,所以我什至无法做到这一点。

帮助!

(这就是我所拥有的)示例代码:导入 UIKit导入 AddressBookUI导入地址簿导入基金会导入核心数据导入核心图形导入 EventKit导入 EventKitUI导入核心基础

类 View Controller :UIViewController {

@IBOutlet var ColorButton: UIButton!

@IBOutlet var StyleButton: UIButton!

@IBOutlet var CutButton: UIButton!

@IBOutlet var MakeupButton: UIButton!


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

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

var eventstore: EKEventStore!
var event: EKEvent!
weak var editViewDelegate: EKEventEditViewDelegate!




@IBAction func ColorButtonPressed(sender: UIButton) {

}

@IBAction func StyleButtonPressed(sender: UIButton) {

}

@IBAction func HaircutButtonPressed(sender: UIButton) {

}

@IBAction func MakeupButtonPressed(sender: UIButton) {

}

最佳答案

为简洁起见,这里有一个建议的方法,如以下代码所示,用于 2 个 Controller (而不是 4 个)。使用适当的命名 segues 到公共(public)处理 Controller 中的每个“下一个处理” Controller 并设置链。这是项目文件的链接:Project file

        import UIKit



class ViewController: UIViewController {

var nextVcId = 0 // defines the button that is pressed



@IBAction func unwindFromOtherControllers(segue: UIStoryboardSegue) {

// In case you want to get back to the main VC

}

@IBAction func btn2Action(sender: UIButton) {

nextVcId = 0

self.performSegueWithIdentifier("commonSegue", sender: sender)

}

@IBAction func btn1Action(sender: UIButton) {

nextVcId = 1

self.performSegueWithIdentifier("commonSegue", sender: sender)

}

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.

}



override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}



override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {



let vc = segue.destinationViewController as! CommonViewController

vc.nextControllerId = nextVcId



}



}

import UIKit



class CommonViewController: UIViewController {

var nextControllerId = 0



@IBOutlet weak var StatusLabel: UILabel!

override func viewDidLoad() {

super.viewDidLoad()

self.StatusLabel.text = "Common"

commonProcessing()

// Do any additional setup after loading the view.

}



override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}



func commonProcessing() {

// do your common processing

if nextControllerId == 0 {

performSegueWithIdentifier("next1Segue", sender: self)



} else {

performSegueWithIdentifier("next2Segue", sender: self)

}

}



}

import UIKit



class Next1ViewController: UIViewController {



@IBOutlet weak var statusLabel: UILabel!

override func viewDidLoad() {

super.viewDidLoad()

self.statusLabel.text = "Next1"

next1Processing()



// Do any additional setup after loading the view.

}



override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}



func next1Processing() {

println("Next 1 Processing")

}





}

import UIKit



class Next2ViewController: UIViewController {



@IBOutlet weak var statusLabel: UILabel!

override func viewDidLoad() {

super.viewDidLoad()

statusLabel.text = "Next 2"

next2Processing()



// Do any additional setup after loading the view.

}



override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}



func next2Processing() {

println("Next 2 Processing")

}





}

处理

关于swift - 通过按钮链接 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30382575/

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