开发者

NSMutableString Null after returning from another View Controller

开发者 https://www.devze.com 2023-03-26 21:40 出处:网络
Can someone tell me why I am getting my NSMutableString to NULL out after returning from another view controller.

Can someone tell me why I am getting my NSMutableString to NULL out after returning from another view controller.

Its completely fine and I am able to use it as long as I dont leave the View Controller its on. But if i Present another view controller and then dismiss it. (bringing me back to 开发者_Python百科my view controller that has my NSMutableString) its all of a sudden NULL and I cannot append to it.

I initialize it like this in the ViewDidLoad.

//initialize mutable string
self.ticketsToSendToServer = [NSMutableString stringWithString:@""];

Do I need to Retain it or something ( i have tried that but it doesnt seem to work ).


stringWithString is a convenience method it returns an NSString that is auto-released. Meaning that the next time the Autorelease pool gets drained, its retain count will be decremented ( -1 ). This is why it is convenient, you do not have to worry about releasing it. However, in your case I think you may want to try:

self.ticketsToSendToServer = [[NSMutableString alloc] initWithString:@""];

which will have a retain count of 1 and will need to be released when you are finished with it.


@property (nonatomatic,copy) NSString *ticketsToSendToServer;

have you declare it as a property

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号