Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 创建一个登录页面。但不要获取和登录_Ios_Objective C_Xcode - Fatal编程技术网

Ios 创建一个登录页面。但不要获取和登录

Ios 创建一个登录页面。但不要获取和登录,ios,objective-c,xcode,Ios,Objective C,Xcode,创建一个登录页面。首先是输入名称和密码,然后移动另一个xib(另一个视图)。名称和密码已保存在CoreData(数据库)中。我使用了通过获取数据(名称和密码)的获取查询,并移动到另一个xib - (IBAction)loginbtn:(id)sender { [self.tx1 resignFirstResponder]; [self.tx2 resignFirstResponder]; if (self.tx1.text.length == 0) {

创建一个登录页面。首先是输入名称和密码,然后移动另一个xib(另一个视图)。名称和密码已保存在CoreData(数据库)中。我使用了通过获取数据(名称和密码)的获取查询,并移动到另一个xib

- (IBAction)loginbtn:(id)sender
{

    [self.tx1 resignFirstResponder];

    [self.tx2 resignFirstResponder];

    if (self.tx1.text.length == 0)
    {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter User Name" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if (self.tx2.text.length == 0)
    {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter Password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
    }

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

context = [appDelegate managedObjectContext];

NSFetchRequest *request= [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Loginform" inManagedObjectContext:context];

NSPredicate *predicate =[NSPredicate predicateWithFormat:@"name==%@ AND password==%@",self.tx1.text, self.tx2.text];

[request setEntity:entity];

[request setPredicate:predicate];

NSError *error;

NSMutableArray *results = [self.managedObjectContext executeFetchRequest:request error:&error];

NSLog(@"The returned results are %@",results);

for (Loginform *anAccount in results)
{
    if ([anAccount.name isEqualToString:self.tx1.text])
    {

        NSLog(@"Your username exists");

        if ([anAccount.password isEqualToString:self.tx2.text])
        {

            NSLog(@"Your pin is correct");

            if([anAccount.name isEqualToString:@"root"])
            {
                homeViewController*home = [[homeViewController alloc]initWithNibName:@"homeViewController" bundle:Nil];

                [self presentViewController:home animated:YES completion:Nil];

            }
            else 
            {

                NSLog(@"Your pin is wrong");
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter Password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

                [alert show];

            }

        }
        else
        {

             NSLog(@"Your username was not found");

             UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter User Name" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

             [alert show];

        }

    }

}

}

无法理解您的问题,请解释清楚您的问题,因为您的编码部分是clearEdit my que。请再次阅读并解决我的问题。您遇到的错误是什么?能否显示您的“保存数据”功能??
- (IBAction)loginbtn:(id)sender
{

    [self.tx1 resignFirstResponder];

    [self.tx2 resignFirstResponder];

    if (self.tx1.text.length == 0)
    {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter User Name" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
    else if (self.tx2.text.length == 0)
    {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please Enter Password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];

    context = [appDelegate managedObjectContext];
    NSFetchRequest *request= [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Loginform" inManagedObjectContext:context];

    NSPredicate *predicate =[NSPredicate predicateWithFormat:@"name==%@ AND password==%@",self.tx1.text, self.tx2.text];
    [request setEntity:entity];
    [request setPredicate:predicate];
    NSError *error;
    NSMutableArray *results = [self.managedObjectContext executeFetchRequest:request error:&error];
    Loginform *anAccount = results.firstObject;
    if(anAccount!=nil){
        if([anAccount.name is equalToString self.tx1.text && [anAccount.password isEqualToString:self.tx2.text]])
        {
            //login success
            homeViewController*home = [[homeViewController alloc]initWithNibName:@"homeViewController" bundle:Nil];
            [self presentViewController:home animated:YES completion:Nil];
        }else{
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@“Username or password is wrong" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [alert show];              
        }
    }
}