Guest User

Untitled

a guest
Mar 9th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  2.  
  3. var badParameters:Bool = true
  4.  
  5. override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
  6. if badParameters {
  7. // your code here, like badParameters = false, e.t.c
  8. return false
  9. }
  10. return true
  11. }
  12.  
  13. - (IBAction)nameChanged:(id)sender {
  14. UITextField *text = (UITextField*)sender;
  15. [nextButton setEnabled:(text.text.length != 0)];
  16. }
  17.  
  18. override func shouldPerformSegueWithIdentifier(identifier: String,sender: AnyObject?) -> Bool {
  19.  
  20. return true
  21. }
  22.  
  23. - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender
  24. {
  25. // Check this identifier is OK or NOT.
  26. }
  27.  
  28. - (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  29. {
  30. // Check valid by codes
  31. if ([self shouldPerformSegueWithIdentifier:identifier sender:sender] == NO) {
  32. return;
  33. }
  34.  
  35. // If this identifier is OK, call `super` method for `-prepareForSegue:sender:`
  36. [super performSegueWithIdentifier:identifier sender:sender];
  37. }
  38.  
  39. -(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
  40. {
  41.  
  42. [self getDetails];
  43.  
  44. if ([identifier isEqualToString:@"loginSegue"])
  45. {
  46.  
  47. if (([_userNameTxtf.text isEqualToString:_uname])&&([_passWordTxtf.text isEqualToString:_upass]))
  48. {
  49.  
  50. _userNameTxtf.text=@"";
  51. _passWordTxtf.text=@"";
  52.  
  53. return YES;
  54. }
  55. else
  56. {
  57. UIAlertView *loginAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Invalid Details" delegate:self cancelButtonTitle:@"Try Again" otherButtonTitles:nil];
  58.  
  59. [loginAlert show];
  60.  
  61. _userNameTxtf.text=@"";
  62. _passWordTxtf.text=@"";
  63.  
  64. return NO;
  65. }
  66.  
  67. }
  68.  
  69. return YES;
  70.  
  71. }
  72.  
  73. -(void)getDetails
  74. {
  75. NSArray *dir=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  76.  
  77. NSString *dbpath=[NSString stringWithFormat:@"%@/userDb.sqlite",[dir lastObject]];
  78.  
  79. sqlite3 *db;
  80.  
  81. if(sqlite3_open([dbpath UTF8String],&db)!=SQLITE_OK)
  82. {
  83. NSLog(@"Fail to open datadbase.....");
  84. return;
  85. }
  86.  
  87. NSString *query=[NSString stringWithFormat:@"select * from user where userName = "%@"",_userNameTxtf.text];
  88.  
  89. const char *q=[query UTF8String];
  90.  
  91. sqlite3_stmt *mystmt;
  92.  
  93. sqlite3_prepare(db, q, -1, &mystmt, NULL);
  94.  
  95. while (sqlite3_step(mystmt)==SQLITE_ROW)
  96. {
  97. _uname=[NSString stringWithFormat:@"%s",sqlite3_column_text(mystmt, 0)];
  98.  
  99. _upass=[NSString stringWithFormat:@"%s",sqlite3_column_text(mystmt, 2)];
  100. }
  101.  
  102. sqlite3_finalize(mystmt);
  103. sqlite3_close(db);
  104.  
  105. }
  106.  
  107. func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
  108. if showDetails() {
  109. return indexPath
  110. }
  111. return nil
  112. }
Add Comment
Please, Sign In to add comment