ios segue unrecognized selector sent to instance - ios

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:.

Related

Using a method a second time gives me an error (IOS)

Im writing this app in objective c (Xcode).
when i use a method in the first time everything goes well, but when i use it the second time it gives me an error.
I tried to debug it and the error goes in the method add tutor in the line if([tutor.userName isEqualToString:userName])
this is the error:
-[__NSCFConstantString userName]: unrecognized selector sent to
instance 0xad14c 2016-02-26 20:10:44.043 project[1258:35474] ***
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFConstantString
userName]: unrecognized selector sent to instance 0xad14c'
this is my code:
- (IBAction)addToFavorite:(id)sender {
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSString * userName = delegate.delegateStr;
Student * student = [[Model instance]getStudentByUserName:userName];
[student addTutor:self.tutor.userName];
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
FavoritesTableViewController * ftvc = [sb instantiateViewControllerWithIdentifier:#"favoritesTableViewController"];
ftvc.favTutors = student.favTutors;
[[NSNotificationCenter defaultCenter] postNotificationName:#"RefreshTable" object:nil userInfo:nil];
}
-(void)addTutor:(NSString*)userName {
BOOL check = YES;
for (Tutor * tutor in self.favTutors) {
if([tutor.userName isEqualToString:userName])
check = NO;
}
if(check)
[self.favTutors addObject:userName];
}
Please help!!
Thanks.
That's failing because you are adding username in your favTutors array instead of objects of Tutor. So when you add first object and then next time your enumerate through self.favTutors you actually have a string object which will not respond to username property.
problem is here at the line i added comment. you are adding an NSString to objects full of Tutor objects. and in second call of this method, in for loop, tutor is actually an NSString and you are trying to call tutor.userName and it doesnt exist in NSString object.
-(void)addTutor:(NSString*)userName {
BOOL check = YES;
for (Tutor * tutor in self.favTutors) {
if([tutor.userName isEqualToString:userName])
check = NO;
}
if(check)
[self.favTutors addObject:userName]; //problem here!!!!
}
My advice is to create tutor object and add it to your array.
-(void)addTutor:(NSString*)userName {
BOOL check = YES;
for (Tutor * tutor in self.favTutors) {
if([tutor.userName isEqualToString:userName])
check = NO;
}
if(check)
{
// create Tutor object and add it to array dont add NSString directly
}
}

BlackRaccoon while downloading a file giving error: unrecognized selector sent to instance 0xcd609f0

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.

UIAlertview not accepting string as message

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.

NSMetadataQueryDidUpdateNotification Not Working

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.

I have set segue but says has no segue with identifier

I have made a demo to log weibo.after I get token jump to other page.
- (void)sinaweiboDidLogIn:(SinaWeibo *)sinaweibo
{
[self saveWeiboInfo];
NSLog(#"uid= %# accessToken= %#", sinaweibo.userID, sinaweibo.accessToken);
[self performSegueWithIdentifier:#"login" sender:self];
}
then turn error after get token:
2013-02-18 17:31:50.683 WeiboTimeline[5690:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<WeiboLoginViewController: 0x712a850>) has no segue with identifier 'login''
the identifier set right.
but in viewdidLoad ,it can jump right.
- (void)viewDidLoad
{
[super viewDidLoad];
NSDictionary *dic = [[NSUserDefaults standardUserDefaults] dictionaryForKey:#"weiboUserData"];
NSString *token = [dic valueForKey:#"access_token"];
NSLog(#"token= %#", token);
if (token != nil) {
[self performSegueWithIdentifier:#"login" sender:self];
}
}
after the code run,when token get the save ,and next time app open can jump right.
why?they are the same code,thanks for you teach.

Resources