我对使用 xCode 还很陌生,如果这个问题看起来很奇怪,我很抱歉。
在我的应用程序中,我希望所有视图和表视图都通过一个对象引导它们的数据库(sqlite3)访问。我已经运行了 openDatabase 函数,但似乎在没有可用时创建新函数的函数存在问题。
当代码在视图本身中时,这一切都可以正常工作,但是集中它使它比我预期的要困难得多:(。
在我的 .h 和 .m 代码下方:
beDbAccess.h
//
// beDbAccess.h
// myDiveApp
//
// Created by Jurgen on 07/09/13.
// Copyright (c) 2013 Dictus. All rights reserved.
//
#import "beObject.h"
#import "sqlite3.h"
@interface beDbAccess : NSObject
{
NSArray *path;
NSString *docPath;
NSString *dbPathString;
NSFileManager *fileManager;
}
@property (nonatomic, retain) NSArray *path;
@property (nonatomic) NSString *docPath;
@property (nonatomic) NSString *dbPathString;
@property (nonatomic) NSFileManager *fileManager;
#pragma functions callable from the outside
NSString *openDatabase();
#pragma functions
-(void)createNewDatabase;
@end
==================
beDbAccess.m
//
// beDbAccess.m
// myDiveApp
//
// Created by Lion on 07/09/13.
// Copyright (c) 2013 Dictus. All rights reserved.
//
// LET EROP DAT JE NOOIT '' gebruikt rond de veldnamen in de WHERE CLAUSE !!!
#import "beDbAccess.h"
@implementation beDbAccess
@synthesize path, dbPathString, docPath, fileManager;
NSMutableArray *arrayOfButtons;
sqlite3 *myDb;
NSArray *path;
NSFileManager *fileManager;
NSString *docPath, *dbPathString;
UIRefreshControl *refreshControl;
NSString *openDatabase()
{
sqlite3 *myDb;
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [path objectAtIndex:0];
NSString *dbPathString = [docPath stringByAppendingPathComponent:@"myDb.db"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:dbPathString])
{
const char *dbPath = [dbPathString UTF8String];
if (sqlite3_open(dbPath, &myDb)==SQLITE_OK)
{
NSLog(@" Create Database: EMPTY ...");
/*!*/ [self createNewDatabase]; // This is where the problem lies... Use of undeclared identifier 'self' :(
} else NSLog(@"#Local: db open...");
}
return dbPathString;
}