2017-08-29 16 views
19

Sự cố cũng giống như tiêu đề. Đây là mã của tôi. Và tôi tìm thấy hoạt động, vuốt từ phải sang trái để xóa trực tiếp, là tính năng mới trong iOS11Sụp đổ nếu vuốt để xóa một ô UITableView nhanh chóng và liên tục trong iOS11

let model = self.customRules.remove(at: indexPath.row) //delete datasource 
self.dao.delete(model: model) //delete data in database 
tableView.beginUpdates() //still crash no matter the line exists or not 
tableView.deleteRows(at: [indexPath], with: .left) //delete cell view 
tableView.endUpdates() 

Đây là nhật ký sự cố.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView internal inconsistency: the _swipedIndexPath cannot be nil if the swipe to delete row is being deleted in _updateRowsAtIndexPaths:withUpdateAction:rowAnimation:usingPresentationValues:' 

Last Exception Backtrace: 
0 CoreFoundation      0x000000018710fd50 <redacted> + 148 
1 libobjc.A.dylib      0x0000000186624528 objc_exception_throw + 56 
2 CoreFoundation      0x000000018710fc0c <redacted> + 0 
3 Foundation       0x0000000187a9bb44 <redacted> + 112 
4 UIKit        0x00000001907c52b8 <redacted> + 648 
5 UIKit        0x00000001906819e4 <redacted> + 140 
...... 
+0

Bạn có nhật ký sự cố không? Ngoài ra, làm thế nào để bạn biết đây là lỗi iOS 11? Bạn đã sử dụng mã này trong phiên bản trước chưa? –

+0

Bạn có thể cung cấp toàn bộ quá trình thực hiện đại biểu không? – iGenio

+0

Dường như iOS 11.2 khắc phục vấn đề này – PatrickDotStar

Trả lời

3

Mã của bạn có vẻ ổn, nhưng đã xảy ra lỗi trong Xcode 9 khi xóa ô. Nếu bạn thử mã của bạn trong Xcode 8 nó có thể sẽ hoạt động. Thanh toán this câu trả lời để biết thêm thông tin.

+0

Cảm ơn rất nhiều. Nhưng dự án của chúng tôi cần một số tính năng iOS11. –

+0

@VictorChoy, bạn sẽ cần đợi cho đến khi Táo sửa lỗi này. Trong thời gian chờ đợi, bạn có thể đảm bảo rằng bạn đã tải xuống phiên bản Xcode mới nhất 9 và hy vọng rằng sự cố được khắc phục sớm. –

+0

Đây là câu trả lời chỉ ling, do đó một bình luận. –

0

Hãy thử sử dụng ví dụ của tôi.

class ViewController: UIViewController { 

    @IBOutlet weak var tableView: UITableView! 

    var data = ["Byba", "Boba", "Gent", "Xpa", "zc", "123", "swipe", "gen", "sw", "xcas", "kjs", "908"] 

    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. 
    } 


} 

// MARK: - UITableViewDelegate 
extension ViewController: UITableViewDelegate { 

    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? { 
     return "delete" 
    } 

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 
     return true 
    } 

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 
     if editingStyle == .delete { 
      tableView.beginUpdates() 
      data.remove(at: indexPath.row) 
      tableView.deleteRows(at: [indexPath], with: .left) 
      tableView.endUpdates() 
     } 
    } 
} 

// MARK: - UITableViewDataSource 
extension ViewController: UITableViewDataSource { 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return data.count 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = UITableViewCell() 
     let item = data[indexPath.row] 

     cell.textLabel?.text = item 

     return cell 
    } 
} 
Các vấn đề liên quan