在我的 SQLite 表中,我有一列“hasSubCountries”,它应该存储简单的 0/1 值 cos SQLite doesn't has distinct boolean type .
在深入研究 stackoverflow 时,我发现了 this question ,但这并没有解决我的问题。
目前在我的数据库中有列:
hasSubCountries integer DEFAULT 0
已将两个子国家的值更改为 1。
我尝试将值读入对象的 DBAccess 类:
countryObj.hasSubCountries=(sqlite3_column_int(statement, 6) == 1);
在 View Controller 代码中:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Country* country = [[self.countries objectAtIndex:[indexPath section]] objectAtIndex:[indexPath row]];
if(country.hasSubCountries==1)
{
SelectedCountry *selCountry=[[SelectedCountry alloc]initWithNibName:@"SelectedCountry" bundle:nil];
[selCountry setTitle:@"Country"];
[selCountry setCountryID:country.countryID];
[self.navigationController pushViewController:selCountry animated:YES];
[selCountry release];
}
else
{
SubCountries *subCountries=[[SubCountries alloc]initWithNibName:@"SubCountries" bundle:nil];
[subCountries setTitle:@"Sub"];
[self.navigationController pushViewController:subCountries animated:YES];
[subCountries release];
}
NSLog(@"%d ... %d",country.hasSubCountries,country.countryID);
}
好吧,NSLog 告诉我无论如何我得到 0,这就是为什么 'if' 将我推到 @"Sub"。 我哪里出错了?
我得到的国家名称和 ID 没有问题。看截图
完整的表定义:
最佳答案
不会是列索引 7 吗?
0 国家ID
1 个国家名称
2 relativeToContinent
3 国家国旗
4 有区域性问题
5 有不同的银行问题
6 有问题
7 个子国家
尝试:
countryObj.hasSubCountries=(sqlite3_column_int(statement, 7) == 1);
不是:
countryObj.hasSubCountries=(sqlite3_column_int(statement, 6) == 1);
关于iphone - 来自 SQLite 的 bool 值总是返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7910478/