2013-03-06 2 views
-1

Я пытаюсь передать NSMutableDictionary в NSNotification другим классам. Но при выпуске NSMutableDictionary сбоев приложений. Может ли кто-нибудь помочь? Я пытаюсь этоУведомление об аварийных ситуациях

NSMutableDictionary *temp = [[NSMutableDictionary alloc]init]; 

NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding]; 
temp = [responseString JSONValue]; 
NSLog(@"webdata is %@",temp); 
NSLog(@"inside usersignup success"); 
[[NSNotificationCenter defaultCenter] postNotificationName:CNotifySignupSucess object:temp]; 
[temp release]; 
+0

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (signupsucessreceived :) имя: объект CNotifySignupSucess: nil]; – jpd

+0

NSMutableDictionary * dict = notification.object; if ([[dict objectForKey: @ "Success"] isEqualToString: @ "1"]) { appDelegate.islogin = TRUE; self.title = nil; [appDelegate.userinfo setObject: [dict objectForKey: @ "user_id"] forKey: @ "userid"]; NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; NSString * strtemp = [NSString stringWithFormat: @ "% @", [dict objectForKey: @ "user_id"]]; [defaults setObject: strtemp forKey: @ "userid"]; – jpd

+0

Роб, я пытаюсь это сделать – jpd

ответ

1

Прежде всего, вы должны прочитать некоторые основы программирования IOS. И,

NSMutableDictionary *temp = [[NSMutableDictionary alloc]init]; 

NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding]; 
temp = [responseString JSONValue]; //----> this line is wrong 

потому, temp указатель указывает на вновь созданный NSMutableDictionary объекта, вы переназначение его на другой объект, возвращаемый JSONValue методом, который autorelease объект, и вы не имеете его, таким образом, может» t release it. Некоторые лучшие способы достижения хотят, чтобы вы хотели бы:

NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding]; 
    NSMutableDictionary *temp = [responseString JSONValue]; 
    NSLog(@"webdata is %@",temp); 
    NSLog(@"inside usersignup success"); 
    [[NSNotificationCenter defaultCenter] postNotificationName:CNotifySignupSucess object:temp]; 
    //NO RELEASING the AUTORELEASE OBJECT!!!! 

ИЛИ:

NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding]; 
    NSMutableDictionary *temp = [[NSMutableDictionary alloc]initWithDictionary:[responseString JSONValue]]; 
    NSLog(@"webdata is %@",temp); 
    NSLog(@"inside usersignup success"); 
    [[NSNotificationCenter defaultCenter] postNotificationName:CNotifySignupSucess object:temp]; 
    [temp release]; 

ИЛИ:

NSMutableDictionary *temp = [[NSMutableDictionary alloc]init]; 

    NSString *responseString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding]; 
    [temp addEntriesFromDictionary:[responseString JSONValue]]; 
    NSLog(@"webdata is %@",temp); 
    NSLog(@"inside usersignup success"); 
    [[NSNotificationCenter defaultCenter] postNotificationName:CNotifySignupSucess object:temp]; 
    [temp release]; 

В последних 2-х случаях я, учитывая, что JSONValue метод возвращает NSDictionary , Goog Luck!

+0

спасибо большое Fahri Azimov я получил это – jpd

Смежные вопросы