Iphone 在iOS上存储.sqlite数据库的位置

Iphone 在iOS上存储.sqlite数据库的位置,iphone,core-data,Iphone,Core Data,在我的应用程序中,我通过CoreData检索、解析XML数据并将其保存到sqlite数据库。这些数据对于应用程序的运行至关重要,并且是脱机使用所必需的。我的最低目标是iOS 4.3 这不是用户生成的,因此我无法将其存储在/Library/Documents iOS 5.0不支持将文件标记为“不备份”的扩展属性,因此,将备份/tmp&/Library/Caches之外的任何内容 资料来源: 因此,我别无选择,只能将数据存储在/Library/Caches文件夹中。iOS可以随时清除此目录 这是

在我的应用程序中,我通过CoreData检索、解析XML数据并将其保存到sqlite数据库。这些数据对于应用程序的运行至关重要,并且是脱机使用所必需的。我的最低目标是iOS 4.3

这不是用户生成的,因此我无法将其存储在/Library/Documents

  • iOS 5.0不支持将文件标记为“不备份”的扩展属性,因此,将备份/tmp&/Library/Caches之外的任何内容
资料来源:

因此,我别无选择,只能将数据存储在/Library/Caches文件夹中。iOS可以随时清除此目录

这是否意味着每当我的应用程序下载新数据(通过xml)并使用…
[managedObjectContext保存:&错误]
... 我必须首先检查MyData.sqlite是否仍然存在?

如果没有,那么我将需要“恢复”CoreData堆栈,然后通知可能需要获取新指针或修改其managedObjectContext的persistentStoreCoordinator的任何其他对象


这个解决方案似乎不正确,但基于iOS 5.0不支持“请勿备份”、苹果的数据存储指南以及清除/Libraray/Caches目录的方式,我不知道还有什么其他替代方案

尼克·洛克伍德的精彩标准路径图书馆;此库按惯例在
库/应用程序支持/脱机数据中存储应用程序私有、不可删减、不可备份、跨应用程序持久更新数据

您是正确的,但对于iOS 5.0及更高版本,任何阻止备份文件的尝试都将无效

在iOS 5.0.1上,备份预防的实现如下():

在iOS 5.1及以上版本上,备份预防的实现如下():

DBDATABASE.H

  #import <Foundation/Foundation.h>
   #import <sqlite3.h>
   #import "DetailtableviewViewController.h"
   @interface DBDatabase : NSObject
    {
    NSString *databasePath;
     }
  +(DBDatabase*)getSharedInstance;
   - (BOOL)createDB;
   - (BOOL) saveData:(NSString*)name email:(NSString *)email  
    password:(NSString *)password confirmpassword:
    (NSString*)confirmpassword           
    age:(NSString*)age department:(NSString*)department;


    - (NSArray*) findingEmailid:(NSString*)Emailid password:
    (NSString*)password;
    - (NSArray*)studentdetailbyTableview:(NSString*)email;

    @end
登记册VI.H

#import <UIKit/UIKit.h>
#import "DBDatabase.h"


@interface RegisterViewController :UIViewController  
   <UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>

 @property (weak, nonatomic) IBOutlet UITextField *usernameText1;
 @property (weak, nonatomic) IBOutlet UITextField *emailidText2;
 @property (weak, nonatomic) IBOutlet UITextField *passwordText3;
 @property (weak, nonatomic) IBOutlet UITextField *confirmpwdText4;
 @property (weak, nonatomic) IBOutlet UITextField *dobText5;
 @property (weak, nonatomic) IBOutlet UITextField *depatmentText6;
@property (strong,nonatomic)NSArray *depmentArray;
- (IBAction)registerButton:(id)sender;
@property (weak, nonatomic) IBOutlet UIPickerView *departmentPicker;
@property (weak, nonatomic) IBOutlet UIButton *registerBttn;
详细表格单元格

#import <UIKit/UIKit.h>

 @interface DetailTableViewCell : UITableViewCell

 @property (weak, nonatomic) IBOutlet UILabel *nameText;
 @property (weak, nonatomic) IBOutlet UILabel *ageText;
 @property (weak, nonatomic) IBOutlet UILabel *departmentText;

 @end

为什么不想备份数据库?如果它对工作非常关键,并且当它从tmp或缓存中清除时,您不想重新创建它,那么您还需要备份。我说得对吗?另见其他类似问题。对于iOS 5,您可以将文件夹标记为不备份(这样可以节省iCloud备份的空间)。苹果对此非常挑剔。嗯,来自拒绝:iOS数据存储指南指出,只有用户使用您的应用程序创建的内容,例如文档、新文件、编辑等,才可以存储在/documents目录中,并由iCloud进行备份。正如dpjanes所说,我的问题是应用程序商店拒绝的结果。Thom_ek,谢谢你的链接,任何一点信息都有帮助
   #import "DBDatabase.h"
   static DBDatabase *sharedInstance = nil;
  static sqlite3 *database = nil;
  static sqlite3_stmt *statement = nil;


@implementation DBDatabase
+(DBDatabase*)getSharedInstance{
if (!sharedInstance) {
    sharedInstance = [[super allocWithZone:NULL]init];
    [sharedInstance createDB];
}
return sharedInstance;
 }

 -(BOOL)createDB{
 NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
// Build the path to the database file
databasePath = [[NSString alloc] initWithString:[docsDir
 stringByAppendingPathComponent: @"sasi.db"]];    
NSLog(@"CREATED DB PATH :%@", databasePath);

BOOL isSuccess = YES;
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: databasePath ] == NO)
{
    const char *dbpath = [databasePath UTF8String];
    if (sqlite3_open(dbpath, &database) == SQLITE_OK)
    {
        char *errMsg;
     const char *sql_stmt ="CREATE TABLE IF NOT EXISTS USERDETAILS 
       (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT, 
      PASSWORD TEXT, CONFIRMPASSWORD TEXT, AGE TEXT, DEPARTMENT 
      TEXT)"; 

        if (sqlite3_exec(database, sql_stmt, NULL, NULL, &errMsg)
            != SQLITE_OK)
        {
            isSuccess = NO;
            NSLog(@"Failed to create table");
        }
        sqlite3_close(database);
        return  isSuccess;
    }
    else {
        isSuccess = NO;
        NSLog(@"Failed to open/create database");
    }
    }
return isSuccess;
 }

 -(BOOL) saveData:(NSString*)name email:(NSString *)email password:
 (NSString *)password confirmpassword:(NSString *)confirmpassword 
  age:(NSString*)age department:(NSString*)department;
  {
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
     NSString *insertSQL = [NSString stringWithFormat:
                           @"INSERT INTO USERDETAILS (name, email,  
  password,confirmpassword,age,department) VALUES (\"%@\", \"%@\", 
   \"%@\",\"%@\", \"%@\", 
 \"%@\")",name,email,password,confirmpassword,age,department ];  

    const char *insert_stmt = [insertSQL UTF8String];
    sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE)
    {
        return YES;
    }
    else {
        return NO;
    }
    //sqlite3_reset(statement);
     }
return NO;
 }
  -(NSArray*) findingEmailid:(NSString*)Emailid password:    
  (NSString*)password;

 {
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
    NSString *selectSql = [NSString stringWithFormat:
                           @"SELECT *from USERDETAILS Where email 
  =\"%@\" and password =\"%@\"",Emailid,password];
    NSLog(@"------>%@",Emailid);

    const char *compare_stmt = [selectSql UTF8String];
    NSMutableArray *resultarray = [[NSMutableArray alloc]init];
    if (sqlite3_prepare_v2(database, compare_stmt,-1, &statement, 
   NULL) == SQLITE_OK)
    {
        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            NSString *userName =[[NSString alloc]initWithUTF8String:
   (const char *)sqlite3_column_text(statement, 1)];
            [resultarray addObject:userName];
            NSString *password =[[NSString alloc]initWithUTF8String:
   (const char *)sqlite3_column_text(statement, 2)];
            [resultarray addObject:password];
            return resultarray;
        }
        else
        {
            NSLog(@"not found");
            return nil;
        }

    }

  }
return nil;
 }
  -(NSArray*)studentdetailbyTableview:(NSString*)email;

 {
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
    NSString *selectSql = [NSString stringWithFormat:
                           @"SELECT name,age,department FROM 
  USERDETAILS Where email =\"%@\"",email];
    NSLog(@"------->%@",email);
    const char *insert_stmt = [selectSql UTF8String];
    NSMutableArray *resultarray = [[NSMutableArray alloc]init];
    if (sqlite3_prepare_v2(database, insert_stmt,-1, &statement, 
  NULL) == SQLITE_OK)
    {
        if (sqlite3_step(statement) == SQLITE_ROW)
        {
            NSString *userName =[[NSString alloc]initWithUTF8String:
   (const char *)sqlite3_column_text(statement, 0)];
            [resultarray addObject:userName];
            NSString *age =[[NSString alloc]initWithUTF8String:(const 
    char *)sqlite3_column_text(statement, 1)];
            [resultarray addObject:age];
            NSString *department =[[NSStrin alloc]initWithUTF8String: 
      (const char *)sqlite3_column_text(statement, 2)];   
            [resultarray addObject:department];

            return resultarray;


        }
        {
            NSLog(@"not found");
            return nil;
        }

    }

}
return nil;
  }

@end
#import <UIKit/UIKit.h>
#import "DBDatabase.h"


@interface RegisterViewController :UIViewController  
   <UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource>

 @property (weak, nonatomic) IBOutlet UITextField *usernameText1;
 @property (weak, nonatomic) IBOutlet UITextField *emailidText2;
 @property (weak, nonatomic) IBOutlet UITextField *passwordText3;
 @property (weak, nonatomic) IBOutlet UITextField *confirmpwdText4;
 @property (weak, nonatomic) IBOutlet UITextField *dobText5;
 @property (weak, nonatomic) IBOutlet UITextField *depatmentText6;
@property (strong,nonatomic)NSArray *depmentArray;
- (IBAction)registerButton:(id)sender;
@property (weak, nonatomic) IBOutlet UIPickerView *departmentPicker;
@property (weak, nonatomic) IBOutlet UIButton *registerBttn;
 #import "RegisterViewController.h"
 #import <UIKit/UIKit.h>
 #import <sqlite3.h>
 #import "DetailtableviewViewController.h"

  @interface RegisterViewController ()
    @end




  @implementation RegisterViewController

 - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.title = @"NEW USER";
_departmentPicker.hidden=YES;
_depmentArray = [[NSArray alloc]initWithObjects:@"Computer 
Science",@"Civil",@"Mechanical",@"Electonic",nil];   
_registerBttn.enabled =NO;
}
//- (BOOL)textField:(UITextField *)textField  
 shouldChangeCharactersInRange:   
(NSRange)range replacementString:(NSString *)string
 //{
 //    NSInteger maxlength = 25;
 //    {
 //        if(textField == _usernameText1)
   //        {
 //            maxlength =15;
 //        }       
  //        else if(textField ==_dobText5)
  //        {
   //            maxlength =2;
  //        }
 //        
 //        NSUInteger length =[textField.text length]+[string length] 
     - range.length;
  //        return !(length >maxlength);
  //        
   //    }
  //}
 -(BOOL) NSStringIsValidEmail:(NSString *)checkString
 {

  }
  #pragma mark textfield delegate

  - (BOOL) textFieldShouldReturn:(UITextField *)textField {

[textField resignFirstResponder];
return YES;
 }
 -(BOOL)textField:(UITextField *)textField 
  shouldChangeCharactersInRange:(NSRange)range replacementString:
  (NSString *)string {
 if ((_usernameText1.text.length >0) && (_emailidText2.text.length 
 >0) && (_passwordText3.text.length >0) &&     
 (_confirmpwdText4.text.length >0) && (_dobText5.text.length >0))
//&& (textField == _depatmentText6)
{
    _registerBttn.enabled =YES;
}
else{
    _registerBttn.enabled =NO;
}
return YES;
 }

- (void)textFieldDidBeginEditing:(UITextField *)textField {
if( (_usernameText1.text.length >0) && (_emailidText2.text.length >0) 
&& (_passwordText3.text.length >0) && (_confirmpwdText4.text.length 
>0) && (_dobText5.text.length >0)  
&& (textField == _depatmentText6)) {

   // _registerBttn.enabled=YES;
    _departmentPicker.hidden=NO;
}
else
{
    //_registerBttn.enabled=NO;
    _departmentPicker.hidden=YES;
  }
  }

 - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }



 #pragma mark-UIPickerView Datasource

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)   
  pickerView
  {
 return 1;
 }
 - (NSInteger)pickerView:(UIPickerView *)pickerView 
 numberOfRowsInComponent:(NSInteger)component   
 {
 return _depmentArray.count;
 }
 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:   
 (NSInteger)row forComponent:(NSInteger)component
 {
return [_depmentArray objectAtIndex:row];
}

 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:
 (NSInteger)row inComponent:(NSInteger)component
 {
 if (self.departmentPicker)
 {
    [_depatmentText6 setText:[NSString stringWithFormat:@"%@",    
    [_depmentArray objectAtIndex:row]]];
    _departmentPicker.hidden=YES;
 }
 }


 - (IBAction)registerButton:(id)sender {

BOOL success = NO;
if ([_usernameText1.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING      ALERT" message:@"Enter your name" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.usernameText1 becomeFirstResponder];
    }];

    [alert addAction:ok];
    [_usernameText1 becomeFirstResponder];
    [self presentViewController:alert animated:YES completion:nil];
  }

   else if([_emailidText2.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter  your email" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)
                         {
                             [self.emailidText2 becomeFirstResponder];

                         }];
    [_emailidText2 becomeFirstResponder];
    [alert addAction:ok];

    [self presentViewController:alert animated:YES completion:nil];
}

else if(![self NSStringIsValidEmail:self.emailidText2.text ]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter your valid emailid" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.emailidText2 becomeFirstResponder];
    }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if ([_passwordText3.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter your password" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.passwordText3 becomeFirstResponder];
    }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if (_passwordText3.text.length<6) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter the password greater then six characters" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.passwordText3 becomeFirstResponder];
    }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if([_confirmpwdText4.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter the confirm password" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.confirmpwdText4 becomeFirstResponder];
    }];
    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];

}
else if (_confirmpwdText4.text.length<6) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter the confirmpassword greater then sixcharacters" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.confirmpwdText4 becomeFirstResponder];
    }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if ([_dobText5.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter your age" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.dobText5 becomeFirstResponder];
    }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}
else if ([_depatmentText6.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter your department" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
        [self.depatmentText6 becomeFirstResponder];
    }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if (![_passwordText3.text isEqualToString:_confirmpwdText4.text]) {

    {
        UIAlertController *alert =[[UIAlertController alloc]init];
        alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter your password" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
            [self.confirmpwdText4 becomeFirstResponder];
        }];

        [alert addAction:ok];
        [self presentViewController:alert animated:YES completion:nil];
    }
}

else {
    success = [[DBDatabase getSharedInstance]saveData:_usernameText1.text email:_emailidText2.text password: _passwordText3.text confirmpassword:_confirmpwdText4.text age:_dobText5.text department:_depatmentText6.text];

_departmentPicker.hidden=YES;

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"SUCCESS ALERT" message:@"New User Registered succesfully" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancelAction = [UIAlertAction
                                   actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
                                   style:UIAlertActionStyleCancel
                                   handler:^(UIAlertAction *action)
                                   {
                                       NSLog(@"Cancel action");
                                   }];

    UIAlertAction *okAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                               style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction *action)
                               {
                                   NSLog(@"OK action");
                                   [self.navigationController popViewControllerAnimated:YES];
                                   _usernameText1.text=@"";_emailidText2.text=@"";_passwordText3.text=@"";_confirmpwdText4.text=@"";_dobText5.text=@"";_depatmentText6.text=@"";
                                   [self performSegueWithIdentifier:@"New User" sender:self];
                               }];

    [alert addAction:cancelAction];
    [alert addAction:okAction];


    [self presentViewController:alert animated:YES completion:nil];
}

if (success == NO) {

    {
        UIAlertController *alert =[[UIAlertController alloc]init];
        alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"NIL" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction * ok =[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:ok];
        [self presentViewController:alert animated:YES

  completion:nil];
    }
   }
   }
  @end
 #import <UIKit/UIKit.h>
 #import <sqlite3.h>
 #import "DBDatabase.h"


 @interface ViewController : UIViewController<UITextFieldDelegate>

 @property (weak, nonatomic) IBOutlet UITextField *emailidText;
 @property (weak, nonatomic) IBOutlet UITextField *passwordText;
    - (IBAction)newregisterButton2:(id)sender;
  - (IBAction)loginButton1:(id)sender;
 @property (weak, nonatomic) IBOutlet UIButton *logBttn;


@end
 #import "ViewController.h"
 #import "DBDatabase.h"
 @interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.title=@"LOGIN FORM";
self.logBttn.enabled =NO;

 }
 -(BOOL) NSStringIsValidEmail:(NSString *)checkString
 {
 }

- (void)textFieldDidBeginEditing:(UITextField *)textField {
if((_emailidText.text.length > 0) && (_passwordText.text.length <10))
{
      _logBttn.enabled =YES;
}
else {
      _logBttn.enabled = NO;

      }
    }
 #pragma mark-UITextFieldDelegate
-(BOOL) textFieldShouldReturn:(UITextField *)textField{

[textField resignFirstResponder];
return YES;
  }
 - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

- (IBAction)newregisterButton2:(id)sender
 {
[self performSegueWithIdentifier:@"add" sender:self];
}

 - (IBAction)loginButton1:(id)sender {

 NSArray *data =[[DBDatabase    
 getSharedInstance]findingEmailid:_emailidText.text 
 password:_passwordText.text];
if( [_emailidText.text isEqualToString:[NSString stringWithFormat:@"%@",[data objectAtIndex:1]]] ||
    [_passwordText.text isEqualToString:[NSString stringWithFormat:@"%@",[data objectAtIndex:2]]]) {

  UIAlertController *alert =[[UIAlertController alloc]init];
   alert =[UIAlertController alertControllerWithTitle:@"SUCCESS ALERT" message:@"New User Login success" preferredStyle:UIAlertControllerStyleAlert];

   UIAlertAction *okAction = [UIAlertAction
                            actionWithTitle:NSLocalizedString(@"OK", @"OK action")
                            style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction *action)
                             {
                                  NSLog(@"OK action");
    [self performSegueWithIdentifier:@"Detail" sender:self];
                                   _emailidText.text=@"";
                                 _passwordText.text=@"";
                              }];


    [alert addAction:okAction];

   [self presentViewController:alert animated:YES completion:nil];
    [self.activityView startAnimating];
   //        [self.activityView stopAnimating];
}

else if(self.emailidText == nil || [self.emailidText.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter your emailid" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle
                         :@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                             [self.emailidText becomeFirstResponder];
                         }];
    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if(![self NSStringIsValidEmail:_emailidText.text ]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter your valid emailid" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle
                         :@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                             [self.emailidText becomeFirstResponder];
                         }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if(self.passwordText == nil || [self.passwordText.text isEqualToString:@""]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter you password" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle
                         :@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                             [self.passwordText becomeFirstResponder];
                         }];

    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else if(![_passwordText.text isEqualToString:[NSString stringWithFormat:@"%@",[data objectAtIndex:2]]]) {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Enter correct password" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle
                         :@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                             [self.passwordText becomeFirstResponder];
                         }];
    [alert addAction:ok];
    [self presentViewController:alert animated:YES completion:nil];
}

else {

    UIAlertController *alert =[[UIAlertController alloc]init];
    alert =[UIAlertController alertControllerWithTitle:@"WARNING ALERT" message:@"Email is not register" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * ok =[UIAlertAction actionWithTitle:@"Not Register" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
        [self performSegueWithIdentifier:@"add" sender:self];
        _emailidText.text=@"";
        _passwordText.text=@"";
    }];

    [alert addAction:ok];
    _emailidText.text=@"";
    _passwordText.text=@"";
    [self presentViewController:alert animated:YES completion:nil];
}
 }

 #pragma mark - Navigation

 // In a storyboard-based application, you will often want to do a  
  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender: 
 (id)sender {

if ([segue.identifier isEqualToString:@"Detail"]) {
    DetailtableviewViewController *obj = 
 segue.destinationViewController;
    obj.mailid = _emailidText.text;
}
// Get the new view controller using [segue     
 destinationViewController].
// Pass the selected object to the new view controller.
}

@end
#import <UIKit/UIKit.h>
#import "DBDatabase.h"

 @interface DetailtableviewViewController :      
 UIViewController<UITableViewDataSource,UITableViewDelegate>

 @property (weak, nonatomic) IBOutlet UITableView *detailView;
    @property (strong,nonatomic)NSString *mailid;

@end
#import "DetailtableviewViewController.h"
 #import "DetailTableViewCell.h"

 @interface DetailtableviewViewController ()

 @end

 @implementation DetailtableviewViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.title = [NSString stringWithFormat:@"%@",self.mailid];

 }

 - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];

 }

  #pragma mark-UITableView datasourse

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return 1;
  }

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section {

return 1;
 }

- (UITableViewCell *)tableView:(UITableView *)tableView 
cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellid = @"cell";
DetailTableViewCell *cell = [tableView 
dequeueReusableCellWithIdentifier:cellid];
NSArray *data=[[DBDatabase 
getSharedInstance]studentdetailbyTableview:[NSString 
stringWithFormat:@"%@",self.title]];

{
    cell.nameText.text = [NSString stringWithFormat:@"%@",[data 
 objectAtIndex:0]];
    cell.ageText.text =[NSString stringWithFormat:@"%@",[data 
 objectAtIndex:1]];
    cell.departmentText.text = [NSString stringWithFormat:@"%@",[data 
 objectAtIndex:2]];
    return cell;
}
 }

 /*
 #pragma mark - Navigation



 @end
#import <UIKit/UIKit.h>

 @interface DetailTableViewCell : UITableViewCell

 @property (weak, nonatomic) IBOutlet UILabel *nameText;
 @property (weak, nonatomic) IBOutlet UILabel *ageText;
 @property (weak, nonatomic) IBOutlet UILabel *departmentText;

 @end
 import "DetailTableViewCell.h"

  @implementation DetailTableViewCell

 - (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}

 @end