因未捕获的异常而终止应用程序'NSInvalidArgumentException'无法识别的选择器发送到实例0x7fdab8596b40'

时间:2016-04-05 06:38:27

标签: swift uitableview uibutton

这是我在单元格中按下按钮时从数组加载数据的代码

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return self.ncNo.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! NCReceivedCell

    cell.labelNCNo.text = self.ncNo[indexPath.section]
    cell.labelDescription.text = self.desc[indexPath.section]
    cell.labelStatus.text = self.status[indexPath.section]
    cell.takeAction.tag = indexPath.section

    cell.takeAction.addTarget(self, action: "takeActionBtn", forControlEvents:  UIControlEvents.TouchUpInside)

    cell.backgroundColor = UIColor(white:1, alpha: 0.5)
    cell.layer.cornerRadius = 15
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
    return cell


}

按钮操作方法

// MARK: Button Action


 @IBAction func takeActionBtn(sender: UIButton) {
        print("Hello")
    }

*我在UITablebView中创建自定义UITableViewCell和UIButton当按下按钮时给出错误定义*

2016-04-05 11:55:23.679 QMS360[1384:51274] -[QMS360.NCReceivedVC takeActionBtn]: unrecognized selector sent to instance 0x7fdab8596b40
2016-04-05 11:55:23.691 QMS360[1384:51274] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[QMS360.NCReceivedVC takeActionBtn]: unrecognized selector sent to instance 0x7fdab8596b40'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000108e3fe65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001088b6deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000108e4848d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000108d9590a ___forwarding___ + 970
    4   CoreFoundation                      0x0000000108d954b8 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x0000000109418194 -[UIApplication sendAction:to:from:forEvent:] + 92
    6   UIKit                               0x00000001095876fc -[UIControl sendAction:to:forEvent:] + 67
    7   UIKit                               0x00000001095879c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
    8   UIKit                               0x0000000109586af8 -[UIControl touchesEnded:withEvent:] + 601
    9   UIKit                               0x00000001098f0ede _UIGestureRecognizerUpdate + 10279
    10  UIKit                               0x0000000109486f8a -[UIWindow _sendGesturesForEvent:] + 1137
    11  UIKit                               0x00000001094881c0 -[UIWindow sendEvent:] + 849
    12  UIKit                               0x0000000109436b66 -[UIApplication sendEvent:] + 263
    13  UIKit                               0x0000000109410d97 _UIApplicationHandleEventQueue + 6844
    14  CoreFoundation                      0x0000000108d6ba31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    15  CoreFoundation                      0x0000000108d6195c __CFRunLoopDoSources0 + 556
    16  CoreFoundation                      0x0000000108d60e13 __CFRunLoopRun + 867
    17  CoreFoundation                      0x0000000108d60828 CFRunLoopRunSpecific + 488
    18  GraphicsServices                    0x000000010cabbad2 GSEventRunModal + 161
    19  UIKit                               0x0000000109416610 UIApplicationMain + 171
    20  QMS360                              0x0000000107c926dd main + 109
    21  libdyld.dylib                       0x000000010c5ef92d start + 1
    22  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

1 个答案:

答案 0 :(得分:2)

动作有一个参数,所以选择器签名实际上是takeActionBtn:(注意结尾的冒号)。您需要更改它或按钮将尝试调用函数的版本而没有不存在的参数。