通过按钮链接视图控制器 [英] Linking View Controllers through button

查看:148
本文介绍了通过按钮链接视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这一切......一个初学者说到这里我遇到我的应用程序一个地步,我已经陷入停滞,不知道做什么或下一个修复。所以任何答案会是AP preciated!

I'm a beginner at all of this...Having said that I've come across a point in my app where I've stalled and don't know what to do or fix next. So any answers would be appreciated!

所以在我的主页视图控制器,我有四个不同类别的四个按钮。
每一类都有自己的问题清单,但他们有一个共同的常规问题名单。一般的问题清单有它自己的视图控制器。
当你点击任何四个按钮,它带给你的一般问题视图。在这种观点的底部,我有一个下一步按钮。

So in my Home View Controller, I have four buttons with four different categories. Each of these categories has its own question list, but they have a common "General Question" list. The general question list has its own view controller. When you click on any of the four buttons, it brings you to the General Question view. At the bottom of this view, I have a "Next" button.

目标:配置Next按钮继续依据又是什么类别的问题列表中的一个最初美元的主视图控制器pssed p $

Goal: Configure the Next button to continue to one of the category's question list based on what is initially pressed in the Home View Controller.

我在连接视图控制器经由出口和行动的按钮。
然而,当我控制+拖动到视图控制器下一步按钮将无法连接。我不知道,我需要把code这个...

I've connected the buttons via outlet and action in the View Controller. However, the Next button will not connect when I control + drag into the View Controller. I'm not sure where I need to put the code for this...

我在想,在code为下一步按钮可能需要有某种条件语句的,但由于它不能连接我甚至不能走到这一步。

I was thinking that the code for the Next button might need to have some kind of conditional statement, but since it won't connect I can't even get that far.

帮助!

(这是我)样品code:
进口的UIKit
进口AddressBookUI
进口通讯簿
进口基金会
进口CoreData
CoreGraphics的进口
进口EventKit
进口EventKitUI
进口的CoreFoundation

(This is what I have) Sample Code: import UIKit import AddressBookUI import AddressBook import Foundation import CoreData import CoreGraphics import EventKit import EventKitUI import CoreFoundation

类的ViewController:UIViewController的{

class 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) {

}

}

推荐答案

下面是如图中code以下为简明起见2控制器(而不是4)建议的方法。从共同处理控制器使用适当的命名塞格斯每个下一个加工控制器,并成立了一个链条。下面是该项目文件的链接:项目文件

Here is a suggested approach as shown in the code below for 2 controllers (instead of 4) for brevity. Use appropriate named segues to each of the "next processing" controllers from the common processing controller and set up a chain. Here is a link to the project file: 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")

    }





    }

处理

这篇关于通过按钮链接视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆