Unknown problem in my code - Console says: unrecognized selector sent to instance - I try to use the MGTwitterEngine
since yesterday I've got a bug in my application and I don't get where it is. Actually I am pretty sure that I did not change anything and that it worked perfectly yesterday.
I do not intent to publish all of the code but I can post my first ViewController, if you want.
The problem occurs in both ViewControllers. I use the MGTwitterEngine-API to send a message to Twitter. As far as I know the bug causing a crash is located in the following line.
MGTwitterEngine *twiit = [[MGTwitterEngine alloc] initWithDelegate:self];
[twiit setUsername:usernamee password:passworde];
I thought there is nothing wrong about it. Am I wrong? usernamee and passworde are NSStrings.
The console returns:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MGTwitterEngine setUsername:password:]: unrecognized selector sent to instance 0x3911fb0'
If there are questions or if it's impossible to solve the problem like that i would agree to send my hole code to somebody for check. It is not very complex and it just has to Views. Stil I just send the code to trustworthy persons with many reputations.
In addition I am sure that there is nothing wrong about the MGTwitterEngine since I did not ever change its code. It worked probably and I even copied a fresh MGTwitterEnginge into the project's folder.
Oh and here the UIAction, which reacts on a button and let the app crash:
- (IBAction) post: (id) sender{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *usernamee;
usernamee = [prefs stringForKey:@"name_preference"];
//everthing works great, I checked, that usernamee got the right Nsstring from the preference
NSString *passworde;
passworde = [prefs stringForKey:@"password_preference"];
MGTwitterEngine * twitter1 = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitter1 setUsername:usernamee password:passworde];
NSLog(@"sendUpdate: connectionIdentifier = %@", [twitter1 sendUpdate:[@""stringB开发者_StackOverflow中文版yAppendingString:twittermessage.text]] ); //It is not important, if I use sendUpdate, getDirectMessagesSinceID and so on...
loadingActionSheet = [[UIActionSheet alloc] initWithTitle:@"Posting to Twitter..." delegate:nil
cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[loadingActionSheet showInView:self.view];
}
This code works fine for me. Are you getting any compiler warnings about the "unrecognized selector"?
It's possible your preferences do not actually contain the values you asked for - in which case it will not have returned strings, and you could be getting the NSInvalidArgument
exception.
You can check this:
if (![passworde isKindOfClass:[NSString class]] || ![usernamee isKindOfClass:[NSString class])
{
NSLog(@"Some problem with your preferences");
}
isKindOfClass Documentation
精彩评论