为什么我的应用程序在字符串值有空格时崩溃?

时间:2012-07-26 14:52:32

标签: iphone ios ipad

我有一个应用程序,我试图从一个视图控制器发送一个字符串到另一个。当字符串没有空格时,一切正常。如果他们确实有空格,那么应用程序就会因内存泄漏而崩溃。这就是我的做法:

RegisterViewController2 *register2viewcontroller = [[RegisterViewController2 alloc] initWithNibName:@"RegisterViewController2" bundle:nil];

     register2viewcontroller.username2=[usernamestring retain];
     register2viewcontroller.email2=[emailstring retain];
     register2viewcontroller.password2=[passwordstring retain];
     register2viewcontroller.date=[agestring retain];
     register2viewcontroller.gender2=[gendustring retain];
     register2viewcontroller.occupation2=[occustring retain];
     [self.navigationController pushViewController:register2viewcontroller animated:YES];

用户名2& usernamestrings是具有非原子和强属性的类变量。有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

你几乎不应该保留那样的字符串。如果您可以展示如何声明属性,那将会有所帮助。

这也可能是一个有用的读物​​:NSString property: copy or retain?