我这样做对吗,因为数组返回的计数为 0。
-(NSArray *)getAllFavourites{
NSMutableArray *arrFavourites = [[NSMutableArray alloc] init];
NSString *query = @"SELECT * FROM tbl_favourites;";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK){
while (sqlite3_step(statement) == SQLITE_ROW ){
char *charSymbols = (char *) sqlite3_column_text(statement, 0);
NSString *strFetchedSymbol = [[NSString alloc] initWithUTF8String:charSymbols];
DBClassFavourites *dbClassFav = [[DBClassFavourites alloc] initWithString:strFetchedSymbol];
[arrFavourites addObject:dbClassFav];
}
sqlite3_finalize(statement);
}
NSLog(@"%i",[arrFavourites count]);
return arrFavourites;
}
我也有这个类来初始化所需的变量。
@implementation DBClassFavourites
-(id) initWithString:(NSString *)symbol
{
self = [super init];
if (self) {
self.strSymbol = symbol;
}
return self;
}
-(void) dealloc
{
[strSymbol release];
[super dealloc];
}
这是从我的 firstviewcontroller init 函数调用它的地方
@implementation FirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
arrFavourites = [[DatabaseManager database] getAllFavourites];
}