簡體   English   中英

按下滑動刪除按鈕時,應用程序崩潰

[英]App crashes when press swiped delete button

當我使用UITableViewCellEditingStyle.Delete時,我的應用程序轉到top_level_code文件並顯示Thread 1:EXC_BAD_ACCESS(code=EXC_I386_GPFLT)

我想要當用戶在uitableview行上向左滑動時顯示出刪除按鈕,而當他按下它時,該行應被刪除。 它有時可以正常工作,但是很多時候它會崩潰,但是當我再次運行該應用程序時,該行將被刪除。 這是我的代碼:

var doItList = [String]()

var stared = false

class ViewController: UIViewController, UITableViewDelegate {

@IBOutlet weak var staredBtn: UIButton!

@IBOutlet weak var addDoItField: UITextField!

@IBOutlet weak var doItTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    if NSUserDefaults.standardUserDefaults().objectForKey("doItList") != nil {

        doItList = NSUserDefaults.standardUserDefaults().objectForKey("doItList") as [String]

    }

}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return doItList.count

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")

    cell.textLabel?.text = doItList[indexPath.row]

    return cell

}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    if editingStyle == UITableViewCellEditingStyle.Delete {

        doItList.removeAtIndex(indexPath.row)

        NSUserDefaults.standardUserDefaults().setObject(doItList, forKey: "doItList")

        doItTableView.reloadData()

    }

}

這是錯誤

無法同時滿足約束條件。 以下列表中至少有一個約束是您不想要的約束。 嘗試以下操作:(1)查看每個約束,並嘗試找出不期望的約束; (2)查找添加了一個或多個不必要約束的代碼並進行修復。 (注意:如果看到的是您不了解的NSAutoresizingMaskLayoutConstraints,請參閱有關UIView屬性的文檔translatesAutoresizingMaskIntoConstraints)(““,”“,”“,”“)

將嘗試通過打破約束來恢復

在UIViewAlertForUnsatisfiableConstraints上創建一個符號斷點,以在調試器中捕獲該斷點。 列出的UIView的UIConstraintBasedLayoutDebugging類別中的方法也可能會有所幫助。 (lldb)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM