使用 DataHelper 类中定义的以下函数返回的值设置标签时获取 EXC_BAD_ACCESS(所有数据库处理在此处完成):
+(NSString *)getCurrentBalanceAndType:(NSString *)account
{
sqlite3_stmt *statement=NULL;
float bal=0;
NSString *type=NULL, *balance_type=NULL;
//String decimalFormat="%.2f";
statement = [DataHelper getDetailsFromAccountBal:account:[DataHelper currentMonth]];
if (sqlite3_step(statement) == SQLITE_ROW)
{
bal = sqlite3_column_double(statement,2);
type = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
}
sqlite3_finalize(statement);
NSString *stringBal=[NSString stringWithFormat:@"%.2f", bal];
type=[[type uppercaseString] stringByAppendingString:@"r"];
balance_type=[[stringBal stringByAppendingString:@" "]stringByAppendingString:type];
[type release];
return balance_type;
}
这就是我在 viewDidLoad 中设置标签的方式:
lbCreditCurrBal.text=[DataHelper getCurrentBalanceAndType:@"Some Text"];
请帮忙。