如何在ios中获取受限制的数据

时间:2014-10-17 06:31:53

标签: ios objective-c

我正在创建一个应用程序,在其中我使用xml解析器获取数据。结果是字符串形式,所以我将regID的值存储在NSString变量val中。现在我想检查self.val是否大于0然后用户导航到其他页面。

 if ([self.val isEqual:@"0"]) {
        NSLog(@"value of string is 0 ");
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops..." message:@"check your EmailID or password " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
    else{
        NSLog(@"regID is fetched and is not null %@",self.val );
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
        UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Home"];
        [[self navigationController] pushViewController:viewController animated:YES];

    }

但是当我输入错误的emailID然后我得到val是0但我导航到主页。 我的if条件中的错误是什么?

1 个答案:

答案 0 :(得分:0)

创建零值NSString变量并检查值:

NSNumber *zeroValue = [NSNumber numberWithInt:0];
NSString *zeroString = [NSString stringWithFormat:@"%@",zeroValue];

if (self.val isEqualToString:zeroString) {
    // SHOW AN ALERT
} else {
   // else part
}