通过 RightBarButtonItem 移动到另一个 Viewcontroller
Move to another Viewcontroller via RightBarButtonItem
我有以下情况:
我在 viewDidLoad:
中创建了一个 rightBarButtonItem
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "New", style: .Plain, target: self, action: "newProject")
我的问题是,如何使用 segue "show (e.g 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"] {
在故事板中给你的 segue 一个标识符(即 "NewProject"
),然后像这样执行它:
func newProject() {
performSegueWithIdentifier("NewProject", sender: self)
}
我有以下情况:
我在 viewDidLoad:
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "New", style: .Plain, target: self, action: "newProject")
我的问题是,如何使用 segue "show (e.g 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"] {
在故事板中给你的 segue 一个标识符(即 "NewProject"
),然后像这样执行它:
func newProject() {
performSegueWithIdentifier("NewProject", sender: self)
}