为什么我会收到“未找到预期的吸气方法”?

时间:2013-02-09 02:54:34

标签: iphone macos xcode4.5

我正在开发一个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

有人可以帮帮我吗?谢谢!

1 个答案:

答案 0 :(得分:0)

这个错误告诉你,你必须需要getter方法,即我们必须为我们的属性编写getter,如果我们合成它们,那么ios在内部为我们实现了getter方法。这就是为什么你必须综合你的属性。

@implementation ViewController
@Synthesize NameField,ageField;//property synthesized
// remaining code
@end