Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9285273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:07:06+00:00 2026-06-18T19:07:06+00:00

It seems like when I insert/register an account on my app for the second

  • 0

It seems like when I insert/register an account on my app for the second time. The textfields on the log in and the sign up page appear to be disabled because I can’t click or type anything on them. Does anyone here know what’s the problem? Here is my code.

Log In:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize tbPassword,tbUsername;
-(void) createTable: (NSString *) UserTable
      withUserField: (NSString *) UserField
      withPassField: (NSString *) PassField;
{
    char *err;
    NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' " "TEXT PRIMARY KEY, '%@' TEXT);", UserTable, UserField,PassField];
    if (sqlite3_exec(users, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) {
        sqlite3_close(users);
        NSAssert(0, @"Could not create table");

    }
    else{
        NSLog(@"table created");
    }
}

-(NSString *) filePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"users.sql"];
}

-(void) openDB {
    if (sqlite3_open([[self filePath]UTF8String],&users) != SQLITE_OK){
        sqlite3_close(users);
        NSAssert(0, @"Database failed to open");
    }
    else{
        NSLog(@"database opened");
    }
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [self openDB];
    [self createTable:@"UserAccount" withUserField:@"Username" withPassField:@"Password"];
    self.tbUsername.delegate=self;
    self.tbPassword.delegate=self;
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

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

- (IBAction)btnLogin:(id)sender {
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM UserAccount WHERE Username = '%s' COLLATE NOCASE and Password = '%s'",[tbUsername.text UTF8String],[tbPassword.text UTF8String]];
    sqlite3_stmt *statement;
    if (sqlite3_prepare(users, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
    {
        if(sqlite3_step(statement)==SQLITE_ROW)
        {
            ViewController3 *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController3"];
            VC.strUsername = self.tbUsername.text;
            [self presentViewController:VC animated:YES completion:nil];

        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Authentication Failed" message:@"Wrong Username/Password!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }

    }
}

- (IBAction)btnRegister:(id)sender {
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [[self tbUsername]resignFirstResponder];
    [[self tbPassword]resignFirstResponder];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return [textField resignFirstResponder];
}
@end

Register:

#import "ViewController2.h"

@interface ViewController2 ()

@end

@implementation ViewController2
@synthesize tbPassword,tbRepass,tbUsername;
-(void) createTable: (NSString *) UserTable
      withUserField: (NSString *) UserField
      withPassField: (NSString *) PassField;
{
    char *err;
    NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' " "TEXT PRIMARY KEY, '%@' TEXT);", UserTable, UserField,PassField];
    if (sqlite3_exec(users, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) {
        sqlite3_close(users);
        NSAssert(0, @"Could not create table");

    }
    else{
        NSLog(@"table created");
    }
}

-(NSString *) filePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"users.sql"];
}

-(void) openDB {
    if (sqlite3_open([[self filePath]UTF8String],&users) != SQLITE_OK){
        sqlite3_close(users);
        NSAssert(0, @"Database failed to open");
    }
    else{
        NSLog(@"database opened");
    }
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [self openDB];
    [self createTable:@"UserAccount" withUserField:@"Username" withPassField:@"Password"];
    self.tbUsername.delegate=self;
    self.tbPassword.delegate=self;
    self.tbRepass.delegate=self;
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

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

- (IBAction)btnRegister:(id)sender
{
    NSString *select = [NSString stringWithFormat:@"SELECT * FROM UserAccount WHERE Username = '%s' COLLATE NOCASE",[tbUsername.text UTF8String]];
    sqlite3_stmt *statement;
    if (sqlite3_prepare(users, [select UTF8String], -1, &statement, nil)==SQLITE_OK)
    {
        if(sqlite3_step(statement)==SQLITE_ROW)
        {

            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Username already exist!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];

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

                UIAlertView *alert2 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please enter a username." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert2 show];
            }
            else if([tbPassword.text length]==0 || [tbRepass.text length]==0)
            {

                UIAlertView *alert3 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Please enter a password." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert3 show];
            }
            else if([tbPassword.text length]>0 && [tbRepass.text length]>0)
            {

                if([tbPassword.text isEqualToString:tbRepass.text])
                {
                    NSLog(@"Password Match");
                    NSString *username = tbUsername.text;
                    NSString *pass = tbPassword.text;

                    NSString *sql = [NSString stringWithFormat:@"INSERT INTO UserAccount ('Username','Password') VALUES ('%@','%@')",username,pass];
                    char *err;
                    if (sqlite3_exec(users, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK)
                    {
                        sqlite3_close(users);
                        NSAssert(0, @"Could not update table)");

                    }
                    else
                    {
                        NSLog(@"table updated");
                        UIAlertView *alert4 = [[UIAlertView alloc]initWithTitle:@"Done" message:@"Account was registered successfully!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                        [alert4 show];
                        ViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
                        VC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

                       [self presentViewController:VC animated:YES completion:nil];

                        tbUsername.text = @"";
                        tbPassword.text = @"";


                    }

                }

                else
                {
                    UIAlertView *alert5 = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Password does not match." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                    [alert5 show];
                }
            }
        }
    }
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    [[self tbUsername]resignFirstResponder];
    [[self tbPassword]resignFirstResponder];
    [[self tbRepass]resignFirstResponder];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    return [textField resignFirstResponder];
}
@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T19:07:07+00:00Added an answer on June 18, 2026 at 7:07 pm

    I just noticed that when I successfully insert data to my database. The page redirects me to the log in while my keyboard is still visible. i’m not sure if i’m correct but when I added the resignFirstResponder to my btnRegister where it redirects me to the log in. The textfields would still work! thanks btw

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I insert a pair (key,value) to my hashmap but it seems like it doesn't
My output does not insert the data for Total Marks correctly, it seems like
I am attempting to make a registration-like page for a small forum. To register
Edit: for some reason it seems like its refreshing the page upon hitting the
I apologize because this seems like such a simple thing. What's the correct way
It seems like the compiler is very close to doing what I want (because
Seems like i need some help with a project. I have a routine ,
Seems like there should be... Right now it just seems like magic that you
Seems like cuke doesn't show the full error message (at least when problem occurs
Seems like a standard approach for an ioc when given a scenario like (C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.