Can someone tell me what is wrong with the following code which I adapted from iOS 5 Developer's Cookbook
- (void) startMonitoringUbiquitousDocumentsFolder
{
// Remove any existing query – stored in local instance variable
if (alertQuery) [alertQuery stopQuery];
// Search for all file names
alertQuery.predicate = [NSPredicate predicateWithFormat: #"NSMetadataItemFSNameKey == '*'"];
alertQuery.searchScopes = [NSArray arrayWithObject:
NSMetadataQueryUbiquitousDocumentsScope];
// Subscribe to query updates
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(alertUserToUpdates:)
name:NSMetadataQueryDidUpdateNotification
object:nil];
[alertQuery startQuery];
}
- (void) alertUserToUpdates
{
NSLog(#"Contents changed in ubiquitous documents folder");
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Home Monitor"
message:#"Something's going on."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Check Recording", nil];
[alertView show];
[self stopMonitoringUbiquitousDocumentsFolder];
}
I get an exception which says the selector alertUserToUpdates: is unrecognized. Why can't it recognize the method which is obviously right next to it?
2013-04-29 18:07:22.458 eyeFun[8231:907] -[RGPViewController alertUserToUpdates:]: unrecognized selector sent to instance 0x1fd506a0
2013-04-29 18:07:22.462 eyeFun[8231:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RGPViewController alertUserToUpdates:]: unrecognized selector sent to instance 0x1fd506a0'
*** First throw call stack:
(0x337eb3e7 0x3b4e6963 0x337eef31 0x337ed64d 0x33745208 0x3373c349 0x34053b7f 0x340ab327 0x3373c349 0x337b810f 0x37880de9 0x340fa657 0x337c0857 0x337c0503 0x337bf177 0x3373223d 0x337320c9 0x3731133b 0x3564e2b9 0x465b5 0x3b913b20)
libc++abi.dylib: terminate called throwing an exception
Because it isn't right next to it.
You're telling it to use a selector named alertUserToUpdates:. You have a method named alertUserToUpdates. The : is significant-- it says that the method takes one argument, but the actual method doesn't take arguments.
Your method should take an argument of type NSNotification.
Related
I'm working on an iOS app and I've encountered a problem during testing: the app crashes when I try to enter my next ViewController and I get these messages:
2014-06-29 14:22:46.674 IOS2 Practica[55472:60b] -[Logger login:]: unrecognized selector sent to instance 0x9242230
2014-06-29 14:22:46.679 IOS2 Practica[55472:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Logger login:]: unrecognized selector sent to instance 0x9242230'
From other cases I've looked up, it might be possible that something happens when I attempt to use "segue" to switch to the next ViewController but I can't pinpoint the exact source.
I append the code segment where I define the segue in my main View Controller:
- (void)logger:(id)sender {
NSString *user = self.username.text;
NSString *pass = self.password.text;
NSString * urlBase = #"http://www.v2msoft.com/clientes/lasalle/curs-ios/login.php?username=lluis&password=seguro";
[JSONHTTPClient getJSONFromURLWithString:urlBase completion:^(id json,JSONModelError *err){
JsonUser * user = [[JsonUser alloc]initWithDictionary:json error:nil];
if(user.succeed) {
self.user_id = user.user_id;
[self performSegueWithIdentifier:#"Login" sender:self];
} else {
NSLog(#"error");
}
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if (_username.text.length == 0 || _password.text.length == 0) {
[[[UIAlertView alloc] initWithTitle:#"Error"
message:#"Algun dels camps és incorrecte o està buit!"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil, nil]
show];
} else {
Supermarket * supermercat = segue.destinationViewController;
supermercat.user_id = self.user_id;
}
}
Thank you in advance for any insight on this topic.
Somewhere in your code (not the bit you posted), you should be calling a login: method on a Logger instance. That method is not defined in Logger and that is why the app crashes.
Pay attention to the : at the end of Login:: possibly you have defined a login method (which does not take any argument), but you are calling it with an argument. Or maybe you would have liked to call logger:.
You can try 2 things out: either you find out where the login: method is called (some button bound to it in Storyboard?) or you rename logger: into login:.
I am using BlackRaccoon to download a file from FTP server. Following is the code:
- (IBAction)download:(id)sender {
downloadData = [NSMutableData dataWithCapacity: 1];
downloadFile = [[BRRequestDownload alloc] initWithDelegate: self];
downloadFile.path = #"psnewsletter.pdf";
downloadFile.hostname = #"server";
downloadFile.username = #"user";
downloadFile.password = #"pswd";
[downloadFile start];
}
Its gives following error
2014-02-20 11:48:43.526 BlackHillPrimarySchool[2036:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainViewController requestFailed:]: unrecognized selector sent to instance 0xcd609f0'
Any help will be appreciated.
requestFailed: is one of the BRRequest delegate method that you must implement in your view controller.
- (void)requestFailed:(BRRequest *)request {
BRRequestError *reqError = request.error;
// check the error, handle as needed.
}
I'm not sure how your code even compiled. This is a required method of the protocol.
I have this response from my webservice but UIAlertview is giving an strange error
I have printed the respnse and just below I called
2013-08-13 15:40:27.463 Ipad Qld[1459:907] Result {
msg = "Form has been sent successfully.";
status = SUCCESS;
}
2013-08-13 15:40:27.465 Ipad Qld[1459:907] -[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0x1f1168e0
2013-08-13 15:40:27.467 Ipad Qld[1459:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0x1f1168e0'
*** First throw call stack:
(0x32dad2a3 0x3ac1197f 0x32db0e07 0x32daf531 0x32d06f68 0x34bb9375 0x34d05c95 0x34d05741 0x6a25b 0x32cfe037 0x336ae2cb 0xa013f 0x9fe35 0x8d1e7 0x336e86fd 0x336281f9 0x33628115 0x32a8a45f 0x32a89b43 0x32ab1fcb 0x32cf374d 0x32ab242b 0x32a1603d 0x32d82683 0x32d81f7f 0x32d80cb7 0x32cf3ebd 0x32cf3d49 0x368aa2eb 0x34c09301 0x43a85 0x3b048b20)
libc++abi.dylib: terminate called throwing an exception
the code is
- (void) contactUsNotificationReceived:(NSNotification *) notification
{
[[ActivityIndicator currentIndicator] hide];
NSDictionary *alertMessage = [notification userInfo];
NSString * alertMessageString = alertMessage[#"NSLocalizedString"];
NSLog(#"Result is waga %#",alertMessageString);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Result" message:alertMessageString delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
Looks like you are passing a NSDictionnary.
A guess, try to change :
NSString * alertMessage; // the object that you think is a NSString
to
NSDictionary * alertMessage;
NSString * alertMessageString = alertMessage[#"msg"];
Good luck.
Your code seems like problem in isEqualToString. The source string is not valid or it is released or its now pointing to Dictionary.
May be your alert string (that you want to describe) it is not NSString but it may be NSDictionary, so check it.
First get your alert message from NSDictionary to NSString...
NSString *alertMessage = [yourDict objectForKey:#"yourKey"];
Now, show your alert Message in Alert...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:#"%#",alertMessage] message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
I hope this will help you.
I want to create a alert from a alert. but it crashes.
I use under code to create a alert:
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:inMessage delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
}
error message is :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSError isEqualToString:]: unrecognized selector sent to instance 0x88b84c0'
it looks like inMessage has been release. so I change inMessage to #"test test". It works but get out wait_fences: failed to receive reply:10004003
How can i do for creating a alert in a alert ?
As others have pointed out in the comments, the issue here is that you have an NSError that is being treated mistakenly as an NSString.
inMessage seems to be your NSError object. This slips through the type system at compile time because userInfo has no knowledge of the types of its elements.
To fix this, you probably want to get the description of the error message and display that instead with something like
NSString *inMessage = [[userInfo objectForKey:#"NSUnderlyingError"] localizedDescription];
i've a piece of code that should get the current location and than put lat and long in a string.
when a new location is found i put it in a NSString
currentLatit = [NSString stringWithFormat:#"%f",newLocation.coordinate.latitude];
currentLongit = [NSString stringWithFormat:#"%f",newLocation.coordinate.longitude];
Than when i press a button i do:
NSLog(currentLatit);
[[UIApplication sharedApplication] openURL:[[NSURL alloc] initWithString: [NSString stringWithFormat:#"http://maps.google.com/maps?saddr=%#,%#&daddr=%#,%#",currentLatit,currentLongit,detailLatitudine,detailLongitudine]]];
but when i execute this, i get this error:
-[__NSCFArray length]: unrecognized selector sent to instance 0x1e1830
2011-11-15 11:29:07.567 Marcovaldo[771:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray length]: unrecognized selector sent to instance 0x1e1830'
*** First throw call stack:
(0x30ae78bf 0x37c8c1e5 0x30aeaacb 0x30ae9945 0x30a44680 0x30a310a9 0x30ac5a97 0x30a42217 0x30a55b8f 0x37b09b9b 0x37b09b3b 0x7253 0x30a41435 0x32a9c9eb 0x32a9c9a7 0x32a9c985 0x32a9c6f5 0x32a9c321 0x32a8f99b 0x30abbb4b 0x30ab9d87 0x30aba0e1 0x30a3d4dd 0x30a3d3a5 0x3366bfed 0x32aaf743 0x2221 0x21e0)
terminate called throwing an exception(gdb)
The error occur on the NSLog execution
realy cannot understand what's wrong whit this simple code...
thanks for any help
-UPDATE-
changed the NSLog as follow:
NSLog(#"%#",currentLatit);
Now the app crash with BAD_ACCESS_EXCEPTION on the NSLog
No, it seems the app crashed at some point other than NSLog. Please clean and build. Or Enable NSZombie and get the exact error location.
Update:
Just do like as following and try.
if( currentLatit )
[currentLatit release];
if( currentLongit )
[currentLongit release];
currentLatit = [[NSString stringWithFormat:#"%f",newLocation.coordinate.latitude] retain];
currentLongit = [[NSString stringWithFormat:#"%f",newLocation.coordinate.longitude] retain];