Create user interface for SettingsViewController using Interface Builder.
/* Set the title of navigation controller */ self.title=@"Settings"; /* By default the color of navigation controller bar is blue. To make it black translucent color:*/ [self.navigationController.navigationBar setTranslucent:YES]; [self.navigationController.navigationBar setTintColor:[UIColor blackColor]]; /* To add Right bar button (Log In) in navigation controller programmatically, use the following code*/ UIBarButtonItem *l_loginButton = [[UIBarButtonItem alloc] initWithTitle:@"Log In" style:UIBarButtonItemStyleBordered target:self action:@selector(loginbuttonClickHandler:)]; [self.navigationItem setRightBarButtonItem:l_loginButton animated:YES]; [l_loginButton release]; /* To add Left bar button (Cancel) in navigation controller programmatically, use the following code*/ UIBarButtonItem *l_cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelbuttonClickHandler:)]; [self.navigationItem setRightBarButtonItem:l_cancelButton animated:YES]; [l_cancelButton release];
/* In Login button, click call back */ /* To create a new secure vault using createVault method. This method also assigns a password which is the appPasscode provided by the user in Settings screen, and salt value to the vault. */ DataVault *l_vault= nil; @try { l_vault = [DataVault createVault:VAULT_NAME password:appPasscode salt:SALT_PASSWORD]; /*Checks if a vault with the same name already exists. This method throws an exception. A newly created vault is in the unlocked state. */ if ([DataVault vaultExists:VAULT_NAME]) { NSLog(@"Vault %@ created",VAULT_NAME); ////Register User and after successful registration add below code to store the settings in DataVault /* Storing the settings in the vault already created and lock the vault. */ [1_vault setString:@"AppConID" value:appConnID]; [l_vault setString:@"EnableHttp" value:YES]; [l_vault setString:@"Hostname" value:@"10.66.176.121"]; [l_vault setString:@"Portnumber" value:@"8000"]; [l_vault setString:@"Username" value:@"supuser"]; [l_vault setString:@"Password" value:@"s3puser"]; [l_vault lock]; } } @catch (DataVaultException *exception) { NSLog(@"Vault creation failed with error %@",[exception description]); if ([DataVault vaultExists:VAULT_NAME]) { NSLog(@"Vault exists before delete vault"); [DataVault deleteVault:VAULT_NAME]; NSLog(@"deleted vault %@ successfully",VAULT_NAME); } }
/*Inside cellfcellForRowAtIndexPath method of tableview, programmatically add UISwitch in third row of first section to determine whether request if HTTP/HTTPS depending on ON/OFF state of UISwitch*/ /* Initializing switch with frame CGRectZero -- equivalent to CGRectMake(0, 0, 0, 0).*/ U ISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectZero]; /* Add switch as accessoryView of tableviewcell */ httpEnableCell.accessoryView = switchView; /* Sets the state of Switch whether ON/OFF using bollean parameter */ [switchView setOn:[[self.m_propDetailDict objectForKey:[NSString stringWithFormat:@"%i",indexPath.row]]boolValue] animated:NO]; /* Add target/action for particular event. The action may optionally include the sender and the event in that order. So whenever switch is tapped, state can be tracked in selector method*/ [switchView addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; ` /* Release the object therefore memory allocated during initialization */ [switchView release];
/* At first launch of application, when user is not registered, pressing Cancel button will shows an alert message pop-up @"User not registered". Once user is registered, then pressing cancel button will push another view controller with list of data (Carriers List in our application). */