微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误:当我尝试单击TableView单元格时,无法识别的选择器发送到实例

如何解决错误:当我尝试单击TableView单元格时,无法识别的选择器发送到实例

编辑

我只能在模拟器中单击表格视图的一个单元格。如果我单击一个单元格(不管是哪个单元格),然后单击任何其他单元格,应用程序就会崩溃。

这是我单击表视图的第二个单元格时遇到的错误

线程1:异常:“-[Goals_V2.FieldTableViewCell字段:]:无法识别的选择器已发送到实例0x7f95b68100c0”

这是代码

FieldTableViewCell.swift

class FieldTableViewCell: UITableViewCell,UITextFieldDelegate {
    
    static let identifier = "FieldTableViewCell"
    
    static func nib() -> UINib {
        return UINib(nibName: "FieldTableViewCell",bundle: nil)
    }
    
    @IBOutlet var field: UITextField!
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        field.placeholder = ("What would you like to do today")
        field.delegate = self
        
    }
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        print("\(textField.text ?? "")")
        return true
    }
    override func setSelected(_ selected: Bool,animated: Bool) {
        super.setSelected(selected,animated: animated)
        var allowsSelection: Bool { true }
    }
}

FirstViewController.swift

class FirstViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    
    
    @IBOutlet var table: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        table.register(FieldTableViewCell.nib(),forCellReuseIdentifier: FieldTableViewCell.identifier)
        table.delegate = self
        table.dataSource = self
        
    }

    
    func tableView(_ tableView: UITableView,numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: FieldTableViewCell.identifier,for: indexPath) as! FieldTableViewCell
        
        return cell
    }

}

表格视图的屏幕截图

如果我单击一个单元格,则可以正常运行,但是如果此后单击另一个单元格,则应用程序将崩溃

https://imgur.com/0PufAN2

线程1的完整堆栈跟踪

以蓝色突出显示的位置是异常断点捕获异常的地方。 我必须为完整堆栈跟踪拍摄两个屏幕截图,因为它无法显示在屏幕上,但是图像从上到下都是链接

https://imgur.com/a/9jTfIPE

在调试控制台中向后跟踪 这是在调试控制台中的bt之后键入(lldb)时在调试控制台中收到的信息

    frame #0: 0x00007fff51253982 libobjc.A.dylib`objc_exception_throw
    frame #1: 0x00007fff23e5eb94 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    frame #2: 0x00007fff49354af0 UIKitCore`-[UIResponder doesNotRecognizeSelector:] + 302
    frame #3: 0x00007fff23e4286c CoreFoundation`___forwarding___ + 1436
    frame #4: 0x00007fff23e44b58 CoreFoundation`__forwarding_prep_0___ + 120
    frame #5: 0x00007fff49326c1d UIKitCore`-[UIApplication sendAction:to:from:forEvent:] + 83
    frame #6: 0x00007fff48cd5baa UIKitCore`-[UIControl sendAction:to:forEvent:] + 223
    frame #7: 0x00007fff48cd5ef2 UIKitCore`-[UIControl _sendActionsForEvents:withEvent:] + 396
    frame #8: 0x00007fff49632d69 UIKitCore`-[UITextField _resignFirstResponder] + 155
    frame #9: 0x00007fff49353dae UIKitCore`-[UIResponder _finishResignFirstResponder] + 358
    frame #10: 0x00007fff496329af UIKitCore`-[UITextField _finishResignFirstResponder] + 48
    frame #11: 0x00007fff49353e89 UIKitCore`-[UIResponder resignFirstResponder] + 140
    frame #12: 0x00007fff49632829 UIKitCore`-[UITextField resignFirstResponder] + 93
    frame #13: 0x00007fff49353ae2 UIKitCore`-[UIResponder becomeFirstResponder] + 661
    frame #14: 0x00007fff49816d52 UIKitCore`-[UIView(Hierarchy) becomeFirstResponder] + 145
    frame #15: 0x00007fff4963163e UIKitCore`-[UITextField becomeFirstResponder] + 182
    frame #16: 0x00007fff495e19c6 UIKitCore`-[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessaryActivatingSelection:] + 195
    frame #17: 0x00007fff495c869f UIKitCore`-[UITextSelectionInteraction _checkForRepeatedTap:gestureLocationOut:] + 275
    frame #18: 0x00007fff495c9245 UIKitCore`-[UITextSelectionInteraction _handleMultiTapGesture:] + 1103
    frame #19: 0x00007fff49326c1d UIKitCore`-[UIApplication sendAction:to:from:forEvent:] + 83
    frame #20: 0x00007fff48e21b4f UIKitCore`-[UITextMultiTapRecognizer onStateUpdate:] + 169
    frame #21: 0x00007fff48eb6358 UIKitCore`-[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 44
    frame #22: 0x00007fff48ec02ba UIKitCore`_UIGestureRecognizerSendTargetActions + 109
    frame #23: 0x00007fff48ebcb89 UIKitCore`_UIGestureRecognizerSendActions + 295
    frame #24: 0x00007fff48ebbeda UIKitCore`-[UIGestureRecognizer _updateGestureForActiveEvents] + 760
    frame #25: 0x00007fff48ead9cb UIKitCore`_UIGestureEnvironmentUpdate + 2745
    frame #26: 0x00007fff48eaced4 UIKitCore`-[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 467
    frame #27: 0x00007fff48eacc5c UIKitCore`-[UIGestureEnvironment _updateForEvent:window:] + 225
    frame #28: 0x00007fff49364277 UIKitCore`-[UIWindow sendEvent:] + 4479
    frame #29: 0x00007fff4933e6d1 UIKitCore`-[UIApplication sendEvent:] + 356
    frame #30: 0x00007fff493c94ce UIKitCore`__dispatchPreprocessedEventFromEventQueue + 7628
    frame #31: 0x00007fff493cc692 UIKitCore`__handleEventQueueInternal + 6584
    frame #32: 0x00007fff493c2f35 UIKitCore`__handleHIDEventFetcherDrain + 88
    frame #33: 0x00007fff23da1c91 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #34: 0x00007fff23da1bbc CoreFoundation`__CFRunLoopDoSource0 + 76
    frame #35: 0x00007fff23da1394 CoreFoundation`__CFRunLoopDoSources0 + 180
    frame #36: 0x00007fff23d9bf8e CoreFoundation`__CFRunLoopRun + 974
    frame #37: 0x00007fff23d9b8a4 CoreFoundation`CFRunLoopRunSpecific + 404
    frame #38: 0x00007fff38c39bbe GraphicsServices`GSEventRunModal + 139
    frame #39: 0x00007fff49325968 UIKitCore`UIApplicationMain + 1605
  * frame #40: 0x0000000107645c2b Goals V2`main at AppDelegate.swift:12:7
    frame #41: 0x00007fff520ce1fd libdyld.dylib`start + 1
    frame #42: 0x00007fff520ce1fd libdyld.dylib`start + 1```

If you need any more information or context about my project,let me kNow and I'll do my best to elaborate. Also,this is my first Stack Overflow question/post so if I'm not following certain etiquettes or something like that,please do let me kNow. Thank you so much for your help!


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。