I have set segue but says has no segue with identifier - ios

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.

Related

On sending message using JSQmessage Lib i get following exception "libc++abi.dylib: terminating with uncaught exception of type NSException"

Updated full image of console Image shows the console containing errorXcode throws this exception when send button is pressed on message view controller toolbar.
DataManager* dm = [DataManager sharedInstance];
NSDictionary* msgdata = #{KChatIdentifier: _chatId,
kMessageToIdentifier : _toIdentifier,
kMessageFromIdentifier : _fromIdentifier,
kMessageText : text,
kMessageType : [NSNumber numberWithInt:MESSAGE_TYPE_TEXT],
kMessageSenderName: dm.currentUser.username,
kMessageSenderImageURL: dm.currentUser.imageURL,
kMessageReceiverName: #"", kMessageReceiverImageURL:#""};
NSLog(#"%#", msgdata);
[[SocketManager sharedInstance] sendText:msgdata];
JSQMessage* newMessage = [JSQMessage messageWithSenderId:self.senderId displayName:self.senderDisplayName text:text];
[_arrMessages addObject:newMessage];
[self checkForDateHeader:date index:_arrMessages.count-1];
[self finishSendingMessage];
}

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
}
}

ios segue unrecognized selector sent to instance

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

Trying to log exceptions to NSUserDefaults

I'm trying to log crashes in my iPhone app by catching all unhandled exceptions and writing the details to the NSUserDefaults. I set it up by adding this to
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
}
and defined the function to handle it like this:
void uncaughtExceptionHandler(NSException *exception) {
NSMutableString *errorString = [NSMutableString new];
[errorString appendFormat:#"Exception Name : %#\n", exception.name];
[errorString appendFormat:#"Exception Reason : %#\n", exception.reason];
[errorString appendString:#"User Info : \n"];
for (NSString *key in [[exception userInfo] allKeys]) {
[errorString appendFormat:#"Key : %# Value : %#\n", key, [[exception userInfo] valueForKey: key]];
}
[errorString appendFormat:#"Call Stack : %#\n", [exception callStackSymbols]];
[[NSUserDefaults standardUserDefaults] setObject:errorString forKey:#"ErrorLog"];
NSLog(#"Exception : %#", errorString);
}
Everything works fine as far as the function being called when there's a crash and the NSLogs print out all the exception details, but nothing ever gets added to the NSUserDefaults, and I have no idea why.
Does anyone have any idea why this wouldn't set an object into the NSUserDefaults?
Thank you for any help...
Try adding this line after you set the object
[[NSUserDefaults standardUserDefaults] setObject:errorString forKey:#"ErrorLog"];
////add this line//////
[[NSUserDefaults standardUserDefaults] synchronize];
///////////////////////
You should call '[[NSUserDefaults standardUserDefaults] synchronize];'
By the way, how come do you want to use 'NSUserDefaults'?
While developing, you can see log in console.
However, if your App has been released once, crash log in user's device is unreachable so it's useless.
What about using logging service like Flurry or Google analytics?

writing or reading to NSUserDefaults while dismissing viewcontroller crashes with Exc bad access

While dismissing the modalView I save the changes in NSUserDefaultsand synchronize them in the method "saveinUserDeaultsObjects".
Now, repeating this process twice crashes the with exc bad access.(i.e presenting and dismissing).
But, if I dismiss viewcontroller after 1 sec delay using perform selector the app works fine.
What can I infer from this ? - I think writing to NSUserdefaults taking some time while the passed object is released.
If it is the case how to handle such situations ?
- (void)dismissViewController {
[Utils saveinUserDeaultsObjects:self.sortVlaue Forkey:#"SortByValue"];
[Utils saveinUserDeaultsObjects:self.state Forkey:#"State"];
[Utils saveinUserDeaultsObjects:self.topic Forkey:#"AOPString"];
[self dismissViewControllerAnimated:YES completion:^{}];
}
Thank You.
Update
+ (void)saveinUserDeaultsObjects:(NSString )valueObject Forkey:(NSString)key {
//NSLog(#"SaveUseref for key: %# object: %#",key, valueObject);
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
[userPreferences setObject:valueObject forKey:key];
[userPreferences synchronize];
}
Update 2
+ (NSString )retriveFromUserDeaultsStringForkey:(NSString)key {
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
NSString *value = nil;
if (userPreferences) value = (NSString *)[userPreferences objectForKey:key];
return value;
}
the crash it ocassionally shows is at reading the "value" object above. Mostly it is EXC bad access and the malloc stack trace is:
12: 0x1c0b85f in -[CFXPreferencesPropertyListSourceSynchronizer createPlistFromDisk]
13: 0x1bdfc56 in -[CFXPreferencesPropertyListSourceSynchronizer synchronizeAlready]

Resources