Objective c ***由于未捕获异常而终止应用程序';NSInvalidArgumentException';已将无法识别的选择器发送到实例

Objective c ***由于未捕获异常而终止应用程序';NSInvalidArgumentException';已将无法识别的选择器发送到实例,objective-c,runtime-error,nsexception,Objective C,Runtime Error,Nsexception,因此,我正在使用asyncsocket库。 我有一个按钮,按下时会向服务器发送字符串。不存在错误,但我得到以下异常: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [key sendData:]: unrecognized selector sent to instance 0x1002f810' *** First throw call stack: (0x18ce

因此,我正在使用asyncsocket库。 我有一个按钮,按下时会向服务器发送字符串。不存在错误,但我得到以下异常:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-

[key sendData:]: unrecognized selector sent to instance 0x1002f810'
*** First throw call stack:
(0x18ce012 0x16f3e7e 0x19594bd 0x18bdbbc 0x18bd94e 0x3f26 0x1707705 0x63b2c0 0x63b258 0x6fc021 0x6fc57f 0x6fb222 0x66ab1d 0x66af02 0x648d4a 0x63a698 0x26b1df9 0x26b1ad0 0x1843bf5 0x1843962 0x1874bb6 0x1873f44 0x1873e1b 0x26b07e3 0x26b0668 0x637ffc 0x46fd 0x2865 0x1)
libc++abi.dylib: terminate called throwing an exception
这是keyViewController.h

@interface keyViewController ()
{
CFURLRef sysSoundTestPath;
GCDAsyncSocket *asyncSocket;

}
 -(IBAction) touchB:(id)sender;
 -(IBAction)touchE:(id)sender;
 -(void)loadViewFromNIB:(NSString *)nibName owner:(id)owner;
 - (void)sendData:(NSString *) dataSend ;
@end
还有,m

@implementation keyViewController
- (void)sendData: (NSString *) dataSend {
    if (asyncSocket == nil) {
        asyncSocket = [(keyAppDelegate *)[[UIApplication sharedApplication] delegate] asyncSocket];
        asyncSocket.delegate = self;
    }

    NSData *data = [dataSend dataUsingEncoding:NSUTF8StringEncoding];

    //write data to server
    [asyncSocket writeData:data withTimeout:-1 tag:0];
    //listen to server for message
    [asyncSocket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:30.0 tag:1];
}

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
    //data from server
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"%@",str);
}

- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag {
    //prepare to read the next message from server again
    [asyncSocket readDataToData:[GCDAsyncSocket CRLFData] withTimeout:30.0 tag:1];
}


- (IBAction)touchB:(id)sender
{

    NSLog(@"down");
    NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
    NSURL* url = [NSURL fileURLWithPath:path];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer(url), &soundID);
    AudioServicesPlaySystemSound(soundID);
    [sender transmitHandle];
     NSString *name =  [sender restorationIdentifier];
    [sender sendData:name];


}

- (IBAction)touchE:(id)sender
{
    NSLog(@"up");
    [sender transmitHandle];
}

-(void)loadViewFromNIB:(NSString *)nibName owner:(id)owner
{


    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:nibName owner:owner options:nil];
    NSArray *subviews = [objects[0]subviews];
    for (UIView *subview in subviews) {
        if ([subview isKindOfClass:[UIButton class]]) {
            UIButton *key = (UIButton *)subview;
            [key addTarget:self action:@selector(touchB:) forControlEvents:UIControlEventTouchDown];
            [key addTarget:self action:@selector(touchE:) forControlEvents:UIControlEventTouchUpInside];

            //NSString *ident = key.restorationIdentifier;
            //NSLog(@"%@",ident);
        }
    }
}

- (void)viewDidLoad

{
    [super viewDidLoad];
    [self.view setMultipleTouchEnabled:YES];
    [self loadViewFromNIB:@"keyViewController" owner:self];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
     //Dispose of any resources that can be recreated.
}

@end

我做错了什么?

iAction的发送者是按下的按钮。sendData是控制器的一种方法。您正在向按下的按钮发送sendData。将发件人更改为self。我不确定您试图发送给send data方法的字符串是什么,但我不确定您的按钮是否具有属性调用restorationIdentifier

- (IBAction)touchB:(id)sender
{

    NSLog(@"down");
    NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
    NSURL* url = [NSURL fileURLWithPath:path];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer(url), &soundID);
    AudioServicesPlaySystemSound(soundID);
    [sender transmitHandle];
     NSString *name =  [sender restorationIdentifier];
    //I'm not sure what string you're trying to send to the send data method.
    NSLog(@"Sending:%@ to sendData method", name);
    [self sendData:name];


}

@estobart这样做了,现在我正在获取/Users/fozbstudios/Desktop/fozbKEY/fozbKEY/classes/keyViewController.m:64:24:在类型为“\u strong id”的对象上找不到属性“name”