我是初学者,我创建了名为MyDatabase的数据库。我想在标签中显示表格中的一些行,我的代码是,请让我知道解决方案,提前谢谢
@interface ViewController ()
{
MyDatabase *data;
NSMutableArray *tickerarray;
}
@end
@implementation ViewController
-(void)action
{
label.text= @"Phase || possession: Jan 2014";
}
- (void)viewDidLoad
{
[super viewDidLoad];
data=[MyDatabase new];
tickerarray=[data OpenMyDatabase:@"SELECT title FROM news_ticker" :@"title"];
time = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(action) userInfo:nil repeats:NO];
[label setFont:[UIFont fontWithName:@"Arial" size:15]];
label.textColor = [UIColor grayColor];
}
@end
编辑:
-(NSMutableArray *)OpenMyDatabase: (NSString *)query:(NSString *)column {
self.databaseName=@"App_Database.sqlite";
FMDatabase *database=[self openDatabase: self.databaseName];
[database open];
NSArray *nsarr= [self storeDatabaseColumnInArray: database: query:column];
[database close];
}
答案 0 :(得分:0)
更新OpenMyDatabase
方法以返回数组(请注意我将其返回类型从NSMutableArray *
更改为NSArray *
):
- (NSArray *)OpenMyDatabase:(NSString *)query
column:(NSString *)column
{
self.databaseName=@"App_Database.sqlite";
FMDatabase *database=[self openDatabase: self.databaseName];
[database open];
NSArray *nsarr= [self storeDatabaseColumnInArray: database: query:column];
[database close];
return nsarr; // Added
}