2016-04-05 25 views
1

這是我從數組讀取數據的代碼,當我在單元格按下按鈕給錯誤終止應用程序由於未捕獲的異常「NSInvalidArgumentException」無法識別的選擇發送到實例0x7fdab8596b40'

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") 
    } 

*我是創建自定義的UITableViewCell和UIButton的內部UITablebView當按下按鈕給錯誤如下定義*

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 

回答

2

該動作有一個參數,所以選擇器簽名實際上是takeActionBtn:(注意最後的冒號)。你需要改變它,否則按鈕將嘗試調用沒有不存在的參數的函數版本。

+0

我試過但不能工作 – iParesh

+0

你得到同樣的錯誤?文本應該稍微改變。該功能在控制器中,是嗎? – Wain

+0

以上給出的答案是很好的工作,謝謝你的回答 – iParesh

相關問題