0

我是初学者,我创建了名为 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];
}
4

1 回答 1

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
}
于 2013-03-01T11:05:47.460 回答