我研究這個特殊的調試輸出是不是超級罕見的後見@IBAction後才調試輸出,但原因幾乎可以有很大的不同。我是iOS開發新手,一直在努力弄清楚爲什麼應用程序崩潰,但無法破解它。我將提供很多不同的代碼片斷,因爲我只是對預測實際上有什麼不妥。斯威夫特應用程序崩潰與(LLDB)作爲一個UIButton發送
我部分一起this video tutorial for a ToDo list以下,而在某些方面有所不同。最值得注意的是,我選擇不從一個選項卡式應用程序模板開始,而是尋找一種展開視圖的方式。
下面是本教程有您所創建的簡單對象管理器類:
import UIKit
var rmndrMgr = ReminderManager()
struct reminder {
var name = "none"
var description = "none"
}
class ReminderManager: NSObject {
var reminders = [reminder]()
func addReminder(name: String, description: String) {
reminders.append(reminder(name: name, description: description))
}
}
下面是我的第一個視圖控制器:
import UIKit
@objc(ToDoListTableViewController)
class ToDoListTableViewController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func unwindToList(segue:UIStoryboardSegue){
// var source = segue.sourceViewController
// as AddToDoItemViewController
// var item: ToDoItem? = source.toDoItem
// if item != nil {
// self.toDoItems.addObject(item)
// self.tableView.reloadData()
// }
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return rmndrMgr.reminders.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Default")
cell.textLabel!.text = rmndrMgr.reminders[indexPath.row].name
cell.detailTextLabel!.text = rmndrMgr.reminders[indexPath.row].description
return cell
}
}
而第二個視圖控制器:
import UIKit
class AddToDoViewController: UIViewController {
@IBOutlet var textReminder: UITextField!
@IBOutlet var textDescription: UITextField!
//Events
@IBAction func addReminder_click(sender: UIButton) {
}
//Touch Functions
//UITextFieldDelegate
//"first responder" is the keyboard. resign it when user presses return key
//basically gets rid of the keyboard when user submit
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.view.endEditing(true)
println("clicked out")
}
}
這裏是我的「添加」視圖實際上是這樣的: [Removed bec澳洲英語我沒有信譽發表圖片] imgur link instead
我有在意見上UIBarButtonItems導航欄。現在,「關閉」和「完成」按鈕(位於導航欄中)執行相同的操作:將用戶退回到主列表。理想情況下,「提交」按鈕(不在導航欄中,只在正常屏幕上)將會將用戶輸入的內容添加到將顯示在另一個視圖上的數組中。 「完成」按鈕可能會被刪除或重構。
當前的行爲,雖然是針對應用與調試文本(LLDB)當我在「提交」按鈕,點擊無論是什麼樣的代碼裏面的動作功能崩潰。我有理由相信它正確地連接起來,因爲我已經試過寫出函數簽名和控件從按鈕拖動到代碼來生成它。
我認爲,問題出在導航欄,因爲這些都從不同的待辦列表教程解除。但是,我無法獲得描述性足夠的日誌來真正瞭解原因或弄清楚如何解決問題。如果需要,我會很樂意從Xcode發佈更多的信息,所以請問。如果有人能幫我識別我的錯誤並從中吸取教訓,我會非常感激。
添加的鏈接刪除的圖像。代碼中的「提交」按鈕在哪裏? –
對不起,您在發佈時正在編輯它。提交按鈕是第二個視圖控制器中的@IBAction – southheat92
您確定您沒有綁定到舊「操作」的提交按鈕的「操作」?選擇界面構建器中的按鈕,然後單擊**顯示連接檢查器**。另外,在iOS項目中命名'UIButton' addReminder_click似乎很愚蠢。你不覺得它應該是'addReminder_tap'或'addReminder'嗎? –