2013-03-06 80 views
-1

我想通过NSMutableDictionaryNSNotification其他类。 但是当释放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 :) name:CNotifySignupSucess object:nil]; – jpd 2013-03-06 05:20:52

+0

NSMutableDictionary * dict = notification.object;如果([[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”]]; [默认setObject:strtemp forKey:@“userid”]; – jpd 2013-03-06 05:21:38

+0

罗布我试图这 – jpd 2013-03-06 05:22:49

回答

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它。一些更好的方法来达到想要你想会是:

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

OR:

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]; 

OR:

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 。祝你好运!

+0

非常感谢法赫里阿兹莫夫我得到了这个 – jpd 2013-03-06 09:01:22

相关问题