ええ、私は新しいので、助けが必要です。テキストが含まれる 2 つのテキストフィールドがあり、それらの 2 つの文字列 (ユーザー名、パスワード) をデータベースで更新したいと考えています。この仕組みがわからないので、どう聞いたらいいのかわからない。Xcode はまったく新しいものです。理解してください。ありがとう!ところで、これが私のコードatmです。
@interface ViewController4 ()
@end
@implementation ViewController4
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.lbName.text=self.strName;
self.lbUser.text = self.strUsername;
[self openDB];
NSString *sql = [NSString stringWithFormat:@"SELECT username,password FROM SUMMARY8 WHERE name = '%s' and theuser = '%s'",[self.lbName.text UTF8String],[self.lbUser.text UTF8String]];
sqlite3_stmt *statement;
if (sqlite3_prepare(account, [sql UTF8String], -1, &statement, nil)==SQLITE_OK)
{
while (sqlite3_step(statement)==SQLITE_ROW){
char *field1=(char *) sqlite3_column_text(statement, 0 );
self.tbUsername.text=[[NSString alloc]initWithUTF8String:field1];
char *field2=(char *) sqlite3_column_text(statement, 1 );
self.tbPassword.text=[[NSString alloc]initWithUTF8String:field2];
}
}
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void) openDB
{
if (sqlite3_open([[self filePath] UTF8String], &account) !=SQLITE_OK){
sqlite3_close(account);
NSAssert(0,@"Database failed to open");
}
else
{
NSLog(@"database opened");
}
}
-(NSString *) filePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:0]stringByAppendingPathComponent:@"account.sql"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btnEdit:(id)sender {
self.btnEdit.enabled=NO;
self.tbUsername.enabled=YES;
self.tbPassword.enabled=YES;
self.btnUpdate.hidden=FALSE;
}
- (IBAction)btnReturn:(id)sender {
FlipsideViewController *FVC = [self.storyboard instantiateViewControllerWithIdentifier:@"FlipsideViewController"];
FVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
FVC.strUsername=self.strUsername;
[self presentViewController:FVC animated:YES completion:nil];
}
- (IBAction)btnUpdate:(id)sender {
[self openDB];
NSString *sql = [NSString stringWithFormat:@"UPDATE SUMMARY8 SET username='1',password='2' WHERE name = '%s' and theuser = '%s'",[self.lbName.text UTF8String],[self.lbUser.text UTF8String]];
sqlite3_stmt *statement;
if (sqlite3_prepare(account, [sql UTF8String], -1, &statement, nil)==SQLITE_OK)
{
}
}
-(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