当两次单击相同的UIButton时,出现此错误,仅在对服务器的请求无法通过时才第二次崩溃。获取isEqualToString:发送到实例错误的无法识别的选择器
-[SendHelloFax isEqualToString:]: unrecognized selector sent to instance 0x12b49150
更新:我用的断点,发现它在崩溃的路线是:
if (!errorMessage || [errorMessage isEqualToString:@""])
{
errorMessage = @"Failed to send fax. Please check your WiFi or 3G connection and try again.";
}
方法:
- (IBAction)sendFaxButtonClicked:(id)sender
{
NSString *errorMessage;
int rcode = [MyDataSource sendFax:self.appointment phone_call_id:self.phone_call_id document_url:self.document_url targetId:self.contact_id targetName:self.name.text targetNumber:self.faxNumber.text coverSheetMessage:self.coverSheetMessage.text errorMessage:&errorMessage];
if (rcode) {
if (!errorMessage || [errorMessage isEqualToString:@""]) {
errorMessage = @"Failed to send fax. Please check your WiFi or 3G connection and try again.";
}
UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @"Error" message:errorMessage delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[someError show];
[someError release];
return;
}
if (!rcode) {
[self dismissModalViewControllerAnimated:FALSE];
}
}
+(int)sendFax:(int)appointment_id phone_call_id:(int)phone_call_id document_url:(NSString*)document_url targetId:(int)contactId targetName:(NSString*)targetName targetNumber:(NSString*)targetNumber coverSheetMessage:(NSString*)coverSheetMessage errorMessage:(NSString**)errorMessage
{
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/ichrono/20110715/60b88126/fax_send/", [self getMyHost]]];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[self addCurrentUserLoginToPostRequest:request];
[request setPostValue:[NSString stringWithFormat:@"%d", contactId] forKey:@"fax_contact_id"];
[request setPostValue:[NSString stringWithFormat:@"%d", appointment_id] forKey:@"appointment_id"];
[request setPostValue:[NSString stringWithFormat:@"%d", phone_call_id] forKey:@"phone_call_id"];
[request setPostValue:document_url forKey:@"url_to_fax"];
[request setPostValue:targetNumber forKey:@"fax_number"];
[request setPostValue:targetName forKey:@"full_name"];
[request setPostValue:coverSheetMessage forKey:@"coversheet_message"];
[request startSynchronous];
NSError *error = [request error];
NSString *responseString;
if (!error) {
responseString = [request responseString];
} else {
return -1;
}
NSMutableDictionary *temp = [responseString JSONValue];
*errorMessage = [temp valueForKey:@"errors"];
if ([[temp valueForKey:@"status"] isEqualToString:@"ok"]) {
return 0;
} else {
return -1;
}
}
您可以尝试将'errorMessage'设置为'nil'(第一行代码)。这是引发异常的行:'if(!errorMessage || [errorMessage isEqualToString:@“”]){'? –