何要将@selector从一个方法参数传递给另一个方法参数?

时间:2013-03-28 07:10:53

标签: ios objective-c

我想这样做但是'performSelectorOnMainThread:recievedDataSelector'会抛出一个无法识别的选择器异常。

-(void)updateStatus
{   
    [self makeRequest:@"http://someplace.com/blah.php"
       onRecievedData:@selector(updateStatusRecievedData)];
}


-(void)makeRequest:(NSString *)url onRecievedData:(SEL) recievedDataSelector
{
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:_operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
     {
             [self performSelectorOnMainThread:recievedDataSelector
                                    withObject:data
                                 waitUntilDone:YES];
     }
}

(void)updateReceivedData:(NSData *) data
{
    NSLog(@"[updateReceivedData]");
}

1 个答案:

答案 0 :(得分:2)

您错过' : '到updateStatusRecievedData方法

-(void)updateStatus
{   
    [self makeRequest:@"http://someplace.com/blah.php"
       onRecievedData:@selector(updateStatusRecievedData:)];
}