我有以下情况:
我在viewDidLoad:
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "New", style: .Plain, target: self, action: "newProject")
我的问题是,如何使用segue“show(例如push)”以编程方式将此按钮移动到另一个Viewcontroller。
我有这样的开头:
func newProject() {
}
但我不知道,因为我是Swift的初学者。
任何帮助都会非常感激!
更新
所以,这是整个区域,出现错误:
class NewProject: UIViewController, UITextFieldDelegate, UITextViewDelegate, CustomPickerDelegate {
@IBOutlet weak var txtProjectName: UITextField!
@IBOutlet weak var tvDescription: UITextView!
@IBOutlet weak var txtStartDate: UITextField!
@IBOutlet weak var txtEndDate: UITextField!
var hud: MBProgressHUD?
var customPicker: CustomPickerView?
var dictProject: NSDictionary!
var projectID: String!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Create new Project"
self.hud = MBProgressHUD(view: self.view)
self.view.addSubview(self.hud!)
self.projectID = ("\(self.dictProject!["id"]!)")
self.populateFields()
}
func populateFields() {
if nil != self.dictProject!["name"] {
self.txtProjectName.text = self.dictProject!["name"] as? String
}
}
错误出现在这一行:
self.projectID = ("\(self.dictProject!["id"]!)")
这一行:
if nil != self.dictProject!["name"] {
答案 0 :(得分:0)
在故事板中为您的segue指定一个标识符(即"NewProject"
),然后执行以下操作:
func newProject() {
performSegueWithIdentifier("NewProject", sender: self)
}