0

登录时,当我输入错误的密码时,屏幕开始闪烁。这是代码:

-(void)ValidateUser
{
    if(userObj)
    {
        if([userObj.userPassword isEqualToString:_txtPassword.text])
        {
            PlistUtility *objPlist = [[PlistUtility alloc] init];
            NSDictionary *loginDict = [objPlist ReadPlist:@"LoginCheck"];
            NSString *isFirstTime = [loginDict objectForKey:@"isFirstTime"];
            NSMutableDictionary *updateLoginDict = [[NSMutableDictionary alloc] init];
            [updateLoginDict setValue:userObj.userId forKey:@"userId"];
            [updateLoginDict setValue:userObj.userName forKey:@"username"];
            sendLabelname = userObj.userName;


        NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
        [standardUserDefaults setObject:sendLabelname forKey:@"usernameLabel"];
        [standardUserDefaults synchronize];         



        [updateLoginDict setObject:_txtCompanyID.text forKey:@"companyId"];
        [updateLoginDict setObject:_txtCompanyName.text forKey:@"companyName"];

        [objPlist WritetoPlist:@"LoginCheck" withData:updateLoginDict];

        NSString *urlString = [NSString stringWithFormat:@"http://demo.creativethoughts.co.in/wifier/GetAllSavedWifi.php?userid=%@",userObj.userId];
        NSString *result = [Server ConnectToServer:urlString :nil :@"GET"];
        NSMutableArray *resultArray = [result JSONValue];
        NSMutableDictionary *wifiDict = [[NSMutableDictionary alloc]init];
        for(int i=0;i<[resultArray count];i++)
        {
            NSMutableDictionary *currentDict = [[NSMutableDictionary  alloc]init];
            currentDict = [resultArray objectAtIndex:i];
            MapWifi *objMappedWifi = [[MapWifi alloc]init];
            objMappedWifi.macAddress = [currentDict objectForKey:@"wifier_wifi_address"];
            objMappedWifi.wifiName = [currentDict objectForKey:@"wifier_wifi_name"];
            objMappedWifi.securityKey = [currentDict objectForKey:@"wifier_secret_pass"];
            [wifiDict setObject:objMappedWifi forKey:[currentDict objectForKey:@"wifier_wifi_address"]];
        }
        NSData *dataWifi = [NSKeyedArchiver archivedDataWithRootObject:wifiDict];
        [objPlist WriteDatatoPlist:@"AddedWifi" withData:dataWifi];
        if([isFirstTime isEqualToString:@"1"])
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                [self performSegueWithIdentifier:@"terms" sender:self];
            });
        }
        else
        {
            [self performSegueWithIdentifier:@"home" sender:self];
        }
    }
    else
    {
        [self performSelectorInBackground:@selector(wrongPassword) withObject:nil];

      //  [self performSelectorOnMainThread:@selector(showAlertMessage) withObject:nil waitUntilDone:NO];
    }
}
else
{

    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"Please select a valid user" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
    });


}
 [_loader stopAnimating];

}

-(void)wrongPassword
{
  dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"Please enter a valid password." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
 });
4

2 回答 2

0

错误在于 UI 元素选择器视图。每当密码出错时,它就会在后台线程上运行。我使用此代码在主线程中运行它,问题得到了解决

**dispatch_async(dispatch_get_main_queue(), ^{
        [self LoadActionSheet];
    });**
于 2013-10-23T07:23:04.670 回答
0

@试试这段代码

-(void)wrongPassword
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"Please enter a valid password." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}
于 2013-10-23T06:27:33.700 回答