I have a ViewController,
i declare
NSString *xTitle at the top in testViewController.m file
when i set the xTitle=@”anytext” in viewload event;
and i tap a button, it shows the UIActionsheet.
i try to read xTitle in UIActionSheet’s clickedButtonAtIndex.
i see the xTitle’s value “anytext”, its ok.
but when i set the xTitle from NSDictionary, it says Invalid.
viewload event;
NSDictionary *results = [jsonString JSONValue];
xTitle = [results valueForKey:@"ContentURL"];
NSLog(@"%@", xTitle);–> it writes the value
but i cant read xTitle in uiactionsheet events. it says invalid.
why does it say “Invalid”?
Since you want the string to outlive the function, you probably need to do:
And of course
releaseit at some subsequent point when you’re finished with it.This doesn’t affect you when using the NSString literal
@"anytext"because constant strings are basically static — that is, they normally stick around for the whole lifetime of your code. You can (and maybe in some pedantic sense should)retainandreleasethese too, but it doesn’t actually do anything to them.(I’m a little bit curious about the scoping of this — if
xTitleis declared at the top of the.mfile, how do you get at it in your action sheet — but I don’t think that’s germane to this problem.)