通过按钮

时间:2015-05-21 19:21:07

标签: swift button xcode6 viewcontroller

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

所以在我的Home View Controller中,我有四个按钮,有四个不同的类别。 这些类别中的每一个都有自己的问题列表,但它们有一个共同的“一般问题”列表。一般问题列表有自己的视图控制器。 当您单击四个按钮中的任何一个时,它将进入“常规问题”视图。在这个视图的底部,我有一个“下一步”按钮。

目标:根据最初在主视图控制器中按下的内容,配置“下一步”按钮以继续进入类别的问题列表之一。

我通过视图控制器中的插座和操作连接按钮。 但是,当我控制+拖动到视图控制器时,“下一步”按钮将无法连接。我不确定我需要把代码放在哪里......

我认为Next按钮的代码可能需要某种条件语句,但由于它不能连接我甚至无法达到那么远。

帮助!

(这就是我所拥有的)示例代码: 导入UIKit 导入AddressBookUI 导入地址簿 进口基金会 导入CoreData 导入CoreGraphics 导入EventKit 导入EventKitUI 导入CoreFoundation

类ViewController: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) {

}

}

1 个答案:

答案 0 :(得分:1)

为简洁起见,下面是针对2个控制器(而不是4个)的代码所示的建议方法。使用适当的命名segue到来自公共处理控制器的每个“下一个处理”控制器并建立一个链。以下是项目文件的链接: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")

    }





    }

处理