gpt4 book ai didi

iphone - 如何在 textView 中显示字符串而不是地址

转载 作者:行者123 更新时间:2023-11-28 18:06:32 27 4
gpt4 key购买 nike

我正在尝试从数据库中获取一个随机字符串 我曾尝试将数组转换为字符串,但是当我单击按钮时,我只能获得地址 谁能帮我如何在我的按钮操作中显示该字符串?

- (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;


}

最佳答案

[db randomQuote] 方法返回用户数组而不是字符串,您可以将其类型转换为用户对象,而不是从中获取您想要的属性!

关于iphone - 如何在 textView 中显示字符串而不是地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14039668/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com