NSString transition between UIViews
I want to use NSString from one UIView in another UIView.
There are two ways how I create NSString in the first UIView.
NSString *firstNameTemp = [[[[html componentsSeparatedByString:@"<first_name>"] objectAtIndex:1] componentsSeparatedByString:@"</first_name>"] objectAtIndex:0]; NSString *lastNameTemp = @"Михаил";
If I use NSLog i get same lines in both cases:
2012-06-15 16:21:54.778 VKLike[22718:707] –Ь–Є—Е–∞–Є–ї 2012-06-15 16:21:54.790 VKLike[22718:707] –Ь–Є—Е–∞–Є–ї
There is an issue with encoding, but if I create UILabel with NSString it shows correct string (Михаил).
In second UIView if use method
- (void) initPhotoViewWithFrame:(CGRect)frame Image:(UIImage *)image Name:(NSString *)name;
When I try to use firstNameTemp I get an Error.
But I get no Error if I use lastNameTemp.
The question is: How to successfully pass the first NSString (firstNameTemp)?
It's a memory management error. You have to retain firstNameTemp (and later release it). Strictly, this is also true for lastNameTemp but the bug doesn't surface because string literals (@"...") are created by the compiler and live as long as the process lives.