Search code examples
objective-ciosxcodexcode4

String Problems


A very stupid question from a noob.

I have an action, that sets the string of a label.

- (IBAction) changeProductText:(NSString *)str{ lblProductTxt.text = str; }

This is the string I want to set that to:

TestText = [NSString stringWithFormat:@"Hi"];

And this is how I am doing it:

[self.navigationController pushViewController:nextController animated:YES];

[nextController changeProductText:TestText];

My problem is that it wont set the string to anything is random whats going into the string. It may crash when I click on the cell it may not, so I am doing something wrong.


Solution

  • stringWithFormat gives you an autoreleased format, without seeing more of the code I'm guessing its hitting an autorelease pool and you're trying to access garbage that was your string.