我正在尝试从数据库中获取一个随机字符串我试图将数组转换为字符串但是当我单击按钮时我只得到地址谁能帮助我如何在我的按钮操作中显示该字符串?
- (IBAction)randBtn:(id)sender {
SendQuoteVC *svc= [[SendQuoteVC alloc]initWithNibName:@"SendQuoteVC" bundle:nil];
DBHandler *db =[[DBHandler alloc]init];
arr =[db randomQuote];
NSMutableString * show = [[NSMutableString alloc] init];
for (NSObject * obj in arr)
{
[show appendString:[obj description]];
}
NSLog(@"The concatenated string is %@", show);
NSString *rs =[NSString stringWithFormat:@" %@",show];
svc.quote=rs;
[self.navigationController pushViewController:svc animated:YES];
}
我的日志信息是
2012-12-26 17:02:46.062 SendQuote[2281:c07] QUERY: SELECT * FROM quotes ORDER BY RANDOM() LIMIT 1
2012-12-26 17:02:46.097 SendQuote[2281:c07] txtQuote is (
"<quoteDC: 0xa9a94c0>"
)
2012-12-26 17:02:46.100 SendQuote[2281:c07] rand is (
"<quoteDC: 0xa9a94c0>"
)
我已将我的用户实体类更改为 quoteDC 类,我的 Db 函数是
-(NSMutableArray *)randomQuote{
NSMutableArray *dataArray =[[NSMutableArray alloc]init];
NSString * sqlStr=[NSString stringWithFormat:@"SELECT * FROM quotes ORDER BY RANDOM() LIMIT 1"];
sqlite3_stmt *ReturnStatement = (sqlite3_stmt *) [self getStatement: sqlStr];
while (sqlite3_step(ReturnStatement)==SQLITE_ROW)
{
@try
{
quoteDC *worddc = [[quoteDC alloc] init];
NSString *userid = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement, 0)];
NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(ReturnStatement, 1)];
worddc.quote_id=[userid integerValue];
worddc.quotes=name;
[dataArray addObject:worddc];
}
@catch (NSException *ept) {
NSLog(@"Exception in %s, Reason: %@", __PRETTY_FUNCTION__, [ept reason]);
}
}
return dataArray;
}