2013-05-29 82 views
0

我按名稱動態調用方法。這是我使用的代碼:試圖使用preformSelector並出現錯誤

NSString *methodName=[NSString stringWithFormat:@"%@HintButton",stringForPredicate]; 
      SEL s = NSSelectorFromString(methodName); 
      [self performSelector:s withObject:hItem]; 

我經過和價值是

AnotherSoundHintButton

我在我的代碼如下方法:

- (void)AnotherSoundHintButton:(HintItem*) hItem { 
     [self PlaySound:hItem.hint]; 
} 

,但是當我運行應用程序我收到以下錯誤:

2013-05-29 12:18:39.945 Game[19668:c07] -[SoundViewController AnotherSoundHintButton]: unrecognized selector sent to instance 0x8c60e90 
2013-05-29 12:18:39.946 Game[19668:c07] Uncaught exception: -[SoundViewController AnotherSoundHintButton]: unrecognized selector sent to instance 0x8c60e90 
2013-05-29 12:18:39.947 Game[19668:c07] Stack trace: (
    0 CoreFoundation      0x01c4202e __exceptionPreprocess + 206 
    1 libobjc.A.dylib      0x019b5e7e objc_exception_throw + 44 
    2 CoreFoundation      0x01ccd4bd -[NSObject(NSObject) doesNotRecognizeSelector:] + 253 
    3 CoreFoundation      0x01c31bbc ___forwarding___ + 588 
    4 CoreFoundation      0x01c3194e _CF_forwarding_prep_0 + 14 
    5 libobjc.A.dylib      0x019c96b0 -[NSObject performSelector:withObject:] + 70 
    6 Game        0x00008ab9 -[SoundViewController alertView:clickedButtonAtIndex:] + 969 
    7 UIKit        0x00ced0bc -[UIAlertView(Private) _buttonClicked:] + 294 
    8 libobjc.A.dylib      0x019c9705 -[NSObject performSelector:withObject:withObject:] + 77 
    9 UIKit        0x008fd2c0 -[UIApplication sendAction:to:from:forEvent:] + 96 
    10 UIKit        0x008fd258 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61 
    11 UIKit        0x009be021 -[UIControl sendAction:to:forEvent:] + 66 
    12 UIKit        0x009be57f -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 578 
    13 UIKit        0x009bd6e8 -[UIControl touchesEnded:withEvent:] + 546 
    14 UIKit        0x0092ccef -[UIWindow _sendTouchesForEvent:] + 846 
    15 UIKit        0x0092cf02 -[UIWindow sendEvent:] + 273 
    16 UIKit        0x0090ad4a -[UIApplication sendEvent:] + 436 
    17 UIKit        0x008fc698 _UIApplicationHandleEvent + 9874 
    18 GraphicsServices     0x02ab8df9 _PurpleEventCallback + 339 
    19 GraphicsServices     0x02ab8ad0 PurpleEventCallback + 46 
    20 CoreFoundation      0x01bb7bf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53 
    21 CoreFoundation      0x01bb7962 __CFRunLoopDoSource1 + 146 
    22 CoreFoundation      0x01be8bb6 __CFRunLoopRun + 2118 
    23 CoreFoundation      0x01be7f44 CFRunLoopRunSpecific + 276 
    24 CoreFoundation      0x01be7e1b CFRunLoopRunInMode + 123 
    25 GraphicsServices     0x02ab77e3 GSEventRunModal + 88 
    26 GraphicsServices     0x02ab7668 GSEventRun + 104 
    27 UIKit        0x008f9ffc UIApplicationMain + 1211 
    28 Game        0x00002724 main + 164 
    29 Game        0x00002635 start + 53 
) 
+0

'[的NSString stringWithFormat:@ 「%@ HintButton:」' - 你需要在結腸 –

回答

1

添加列(:) AnotherSoundHintButton

AnotherSoundHintButton: 
+0

好的,謝謝,我只是整理出來。 –

2

試試這個:

NSString *methodName=[NSString stringWithFormat:@"%@HintButton:",stringForPredicate]; 

「HintButton」之後的冒號很重要。

相關問題