iphone - 来自 SQLite 的 bool 值总是返回 0

标签 iphone objective-c ios sqlite

在我的 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 没有问题。看截图

enter image description here

完整的表定义:

enter image description here

最佳答案

不会是列索引 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/

相关文章:

iphone - 应用程序中任何位置的持久 View

iphone - 滚动到 UIScrollView 中的位置

ios - [[UIApplication sharedApplication] currentUserNotificationSettings].types 的调用总是返回 UIUserNotificationTypeNone

ios - iOS 9 中的自定义 UIViewController 转换错误

iphone - 通知中心和 'repeatInterval' 中的唯一条目

ios - Xcode 要求我将属性重新声明为实例变量

iphone - 在 xCode 中加速编译

ios - UIButton - 设置属性并在按下按钮时使用它

ios - CloudKit 无法通过约束与核心数据同步

objective-c - 如何制作一个移动按钮?