0

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

iWheelBuy
  • 5,470
  • 2
  • 37
  • 71
  • As it shows correct string in label then pass yourlable.text (it is also string ) to another view. – Paresh Navadiya Jun 15 '12 at 08:40
  • That's the most undesirable way. Because in first UIView I have only UIWebView – iWheelBuy Jun 15 '12 at 08:44
  • >> There is an issue with encoding, but if I create UILabel with NSString it shows correct string (Михаил). -- take a look on my question http://stackoverflow.com/questions/10950805/debugger-console-encoding-in-xcode-is-broken -- hope it helps – Oleg Trakhman Jun 15 '12 at 09:19

1 Answers1

1

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.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • Great! It works! One more question: should I release it in initPhotoViewWithFrame method or in first UIView dealloc? – iWheelBuy Jun 15 '12 at 08:53