我正在开发一个 iphone 数据库应用程序,我得到“未找到预期的 getter 方法”。我不明白为什么我会收到这条消息。我尝试了各种故障排除。它在这行代码中:
NSString *inserStmt = [NSString stringWithFormat:@"INSERT INTO PERSONS(NAME,AGE) values ('%s' '%d')",[self.Namefield.text UTF8String],[self.ageField.text intValue]];
这是代码:
#import "ViewController.h"
@interface ViewController ()
{
NSMutableArray *arrayOfPerson;
sqlite3 *personDB;
NSString *dbPathString;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
arrayOfPerson = [[NSMutableArray alloc]init];
[[self myTableView]setDelegate:self];
[[self myTableView]setDataSource:self];
[self createOrOpenDB];
}
-(void)createOrOpenDB
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [path objectAtIndex:0];
dbPathString = [docPath stringByAppendingPathComponent:@"persons.db"];
char *error;
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:dbPathString]) {
const char *dbPath = [dbPathString UTF8String];
if (sqlite3_open(dbPath, &personDB)==SQLITE_OK) {
const char *sql_stmt = "CREATE TABLE IF NOT EXISTS PERSONS (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, AGE INTEGER)";
sqlite3_exec(personDB, sql_stmt, NULL, NULL, &error);
sqlite3_close(personDB);
}
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrayOfPerson count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc ]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
Person *aPerson = [arrayOfPerson objectAtIndex:indexPath.row];
cell.textLabel.text = aPerson.name;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", aPerson.age];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)AddPersonButton:(id)sender {
if (sqlite3_open([dbPathString UTF8String], &personDB)==SQLITE_OK) {
NSString *inserStmt = [NSString stringWithFormat:@"INSERT INTO PERSONS(NAME,AGE) values ('%s' '%d')",[self.Namefield.text UTF8String],[self.ageField.text intValue]];
}
}
- (IBAction)DisplayPersonButton:(id)sender {
}
- (IBAction)deletePersonButton:(id)sender {
}
@end
有人能帮帮我吗?谢谢!