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)?

Answers


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.


Need Your Help

Form Based Authentication problem?

c# .net asp.net visual-studio security

i have 2 pages : Login.aspx and Satis.aspx. i redirected from Login.aspx to Satis.aspx if authentication is correct . if i signout from satis i redirected to Login.aspx. But if i write satis.aspx' ...

How to Best Run Hadoop on Single Machine?

hadoop parallel-processing virtual-machine processing-efficiency linux-containers

I have access to a computer running Linux with 20 cores, 92 GB of RAM, and 100 GB of storage on an HDD. I would like to use Hadoop for a task involving a large amount of data (over 1M words, over 1...