简体   繁体   English

断言没有重用表单元格的索引路径

[英]Assert no index path for table cell being reused

I have a UITableView with custom UITableViewCell s with UITextField s inside it. 我有一个带有自定义UITableViewCellUITableView其中包含UITextField

I want to show the keyboard when the user tap the cell. 我想在用户点击单元格时显示键盘。 I'm doing something like this: 我正在做这样的事情:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

     guard let cell = tableView.dequeueReusableCell(withIdentifier: "FormCell", for: indexPath) as? FormTableViewCell else {
        return
     }

    cell.textField.becomeFirstResponder()
}

But when I run the app on an iPad, tap the cell and try to close the keyboard with the "close key", I get this error: 但是,当我在iPad上运行该应用程序时,点击该单元并尝试使用“关闭键”关闭键盘,则会出现此错误:

[Assert] no index path for table cell being reused [声明]没有重用表单元格的索引路径

This is the entire error I got: 这是我得到的整个错误:

* thread #1: tid = 0x7f323, 0x00000001021d5cd8 libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 56, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1021d5cd8)
  * frame #0: 0x00000001021d5cd8 libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 56
frame #1: 0x00000001010ab9ec PullToDismiss`@objc PullToDismiss.tableView(UITableView, didEndDisplaying : UITableViewCell, forRowAt : IndexPath) -> () + 104 at PullToDismiss+Proxy.swift:0
frame #2: 0x000000018fb29c9c UIKit`-[UITableView _reuseTableViewCell:withIndexPath:didEndDisplaying:] + 304
frame #3: 0x000000018fa13b58 UIKit`-[UITableView _setIsAncestorOfFirstResponder:] + 1028
frame #4: 0x000000018f8bc288 UIKit`+[UIView(Internal) _setIsResponderAncestorOfFirstResponder:startingAtFirstResponder:] + 216
frame #5: 0x000000018f8bc02c UIKit`-[UIWindow _setFirstResponder:] + 112
frame #6: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #7: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #8: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #9: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #10: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #11: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #12: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #13: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #14: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #15: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #16: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #17: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #18: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #19: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #20: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #21: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #22: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #23: 0x000000018fb973bc UIKit`-[UIResponder _setFirstResponder:] + 80
frame #24: 0x000000018fae6ec0 UIKit`-[UIView _setFirstResponder:] + 92
frame #25: 0x000000018f928ecc UIKit`-[UITextField _resignFirstResponder] + 300
frame #26: 0x000000018f8ff374 UIKit`-[UIResponder _finishResignFirstResponder] + 296
frame #27: 0x000000019024d2d0 UIKit`-[UITextField _finishResignFirstResponder] + 52
frame #28: 0x000000018f8a36d0 UIKit`-[UIResponder resignFirstResponder] + 284
frame #29: 0x000000018f928bc8 UIKit`-[UITextField resignFirstResponder] + 136
frame #30: 0x000000018fc25978 UIKit`-[UIKeyboardImpl dismissKeyboard] + 544
frame #31: 0x000000018f9be760 UIKit`-[UIKeyboardLayoutStar continueFromInternationalActionForTouchUp:withActions:timestamp:interval:didLongPress:prevActions:executionContext:] + 2544
frame #32: 0x000000018f9bdb7c UIKit`-[UIKeyboardLayoutStar completeSendStringActionForTouchUp:withActions:timestamp:interval:didLongPress:prevActions:executionContext:] + 784
frame #33: 0x000000018f9b1684 UIKit`-[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:] + 4712
frame #34: 0x000000018fc3211c UIKit`__45-[UIKeyboardLayout touchUpTaskForTouchState:]_block_invoke + 228
frame #35: 0x000000018f821b14 UIKit`-[UIKeyboardTaskQueue continueExecutionOnMainThread] + 384
frame #36: 0x000000018fc31dd0 UIKit`-[UIKeyboardLayout _touchEndedProcessingForTouches:] + 344
frame #37: 0x000000018f82c0c4 UIKit`-[UIWindow _sendTouchesForEvent:] + 2484
frame #38: 0x000000018f827328 UIKit`-[UIWindow sendEvent:] + 2988
frame #39: 0x000000018f7f7da0 UIKit`-[UIApplication sendEvent:] + 340
frame #40: 0x000000018ffe175c UIKit`__dispatchPreprocessedEventFromEventQueue + 2736
frame #41: 0x000000018ffdb130 UIKit`__handleEventQueue + 784
frame #42: 0x00000001898f6b5c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
frame #43: 0x00000001898f64a4 CoreFoundation`__CFRunLoopDoSources0 + 524
frame #44: 0x00000001898f40a4 CoreFoundation`__CFRunLoopRun + 804
frame #45: 0x00000001898222b8 CoreFoundation`CFRunLoopRunSpecific + 444
frame #46: 0x000000018b2d6198 GraphicsServices`GSEventRunModal + 180
frame #47: 0x000000018f8627fc UIKit`-[UIApplication _run] + 684
frame #48: 0x000000018f85d534 UIKit`UIApplicationMain + 208
frame #49: 0x00000001003da970 `main + 140 at AppDelegate.swift:15
frame #50: 0x00000001888055b8 libdyld.dylib`start + 4

And the app just crash. 而且应用程序崩溃了。 It crash also if I scroll the UITableView to the top. 如果将UITableView滚动到顶部,也会崩溃。 How can I prevent that to happend? 如何防止这种情况发生?

try this method to get the cell, what you are doing is creating new one. 尝试使用此方法获取单元格,您正在做的是创建新单元格。

if let cell = tableView.cellForRow(at: indexPath) as? FormTableViewCell {
    cell.becomeFirstResponder
} else {
..dostuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有索引路径表格单元格在Swift中重用 - No index path for table cell being reused in Swift 没有重用表单元格的索引路径 - No index path for table cell being reused iOS 6/7中“无法使用表格单元索引路径”消息的含义是什么? - What is the meaning of the “no index path for table cell being reused” message in iOS 6/7? 核心数据:没有重用表单元的索引路径,单元消失了 - Core Data: no index path for table cell being reused, Cells disappearing “表单元没有索引路径被重用”导致应用程序崩溃 - “no index path for table cell being reused” leading to app crash 自定义表格单元格TextField:没有重用表格单元格的索引路径Swift Xcode6 Beta 6 - Custom Table Cell TextField: no index path for table cell being reused Swift Xcode6 Beta 6 在执行UItableView委托/数据源方法之前,控制台中显示“之前没有重用表格单元的索引路径”消息 - before executing UItableView delegate/datasource method “no index path for table cell being reused before” message is displayed in console PickerView没有显示任何值。 它发出警告,如表单元没有索引路径被重用? - PickerView doesn't show any value. It gives warning like no index path for table cell being reused? 无法访问表格视图单元的索引路径 - Index Path for the table view cell is not being accessible 单元被过度使用 - Cell is being overzealously reused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM