当前位置:K88软件开发文章中心编程语言APP编程iOS → 文章内容

iOS SQLite数据库

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 13:42:20

xtField *departmentTextField; IBOutlet UITextField *yearTextField; IBOutlet UITextField *findByRegisterNumberTextField; IBOutlet UIScrollView *myScrollView;}-(IBAction)saveData:(id)sender;-(IBAction)findData:(id)sender;@end 12、更新ViewController.m,如下所示 #import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *) nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view from its nib.}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}-(IBAction)saveData:(id)sender{ BOOL success = NO; NSString *alertString = @"Data Insertion failed"; if (regNoTextField.text.length>0 &&nameTextField.text.length>0 && departmentTextField.text.length>0 &&yearTextField.text.length>0 ) { success = [[DBManager getSharedInstance]saveData: regNoTextField.text name:nameTextField.text department: departmentTextField.text year:yearTextField.text]; } else{ alertString = @"Enter all fields"; } if (success == NO) { UIAlertView *alert = [[UIAlertView alloc]initWithTitle: alertString message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }}-(IBAction)findData:(id)sender{ NSArray *data = [[DBManager getSharedInstance]findByRegisterNumber: findByRegisterNumberTextField.text]; if (data == nil) { UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Data not found" message:nil delegate:nil cancelButtonTitle: @"OK" otherButtonTitles:nil]; [alert show]; regNoTextField.text = @""; nameTextField.text =@""; departmentTextField.text = @""; yearTextField.text =@""; } else{ regNoTextField.text = findByRegisterNumberTextField.text; nameTextField.text =[data objectAtIndex:0]; departmentTextField.text = [data objectAtIndex:1]; yearTextField.text =[data objectAtIndex:2]; }}#pragma mark - Text field delegate-(void)textFieldDidBeginEditing:(UITextField *)textField{ [myScrollView setFrame:CGRectMake(10, 50, 300, 200)]; [myScrollView setContentSize:CGSizeMake(300, 350)];}-(void)textFieldDidEndEditing:(UITextField *)textField{ [myScrollView setFrame:CGRectMake(10, 50, 300, 350)];}-(BOOL) textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES;}@end 输出 现在当我们运行应用程序时,我们就会获得下面的输出,我们可以在其中添加及查找学生的详细信息

上一页  [1] [2] 


iOS SQLite数据库