Hey all, this should be a simple task but for some reason i am making it harder... I am try开发者_如何学Pythoning to save some text from an XML file to a NSString. But when i debug it, the string says "Out of scope".
Here is my code:
in my .h file:
@interface RootViewController : UIViewController<MBProgressHUDDelegate> {
NSString *thePW;
}
and my .m file:
NSString *thePW;
...
- (void)viewDidLoad {
...
if(e == nil){
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
thePW = response; // <-- this is where it has "Out of scope"
[response release];
}
}
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != [alertView cancelButtonIndex])
{
if (thePW == @"0000")
{
NSLog(@"correct!");
}
}
}
You may also try:
thePW = [NSString stringWithFormat:@"%@",response]; // to assign the string value.
and while comparing strings:
(thePW isEqualToString @"0000")
Drop the redeclaration of thePW in your .m file
Also, if you want to keep the value of response in thePW be sure to retain it as well.
精彩评论