【问题标题】:How can I modify NSMutableArray property?如何修改 NSMutableArray 属性?
【发布时间】:2012-01-02 16:40:18
【问题描述】:

我使用 2 个 sqlite db 文件。

1) 从一个 sqlite db 中填充项目。

@property (nonatomic, strong) NSMutableArray *items;  

.......

FMResultSet *results = [db1 executeQuery:query];

    while ([results next]) {

        Book *book = [[Book alloc] init];

        book.content = [results stringForColumn:@"Zcontent"];
        book.title   = [results stringForColumn:@"Ztitle"];
        book.idx     = [results intForColumn:@"Zidx"];

        book.highlight_YN  = NO;

        [items addObject:book];
        [book release];
    }

2)然后,从其他-B- sqlite db中选择项目。

FMDatabase *userDB = [FMDatabase databaseWithPath:userfmdbPath];  
NSString *query2 = [NSString stringWithFormat:@"SELECT zidx, highlight_YN FROM zHighlight where zbook = %d and zchapter = %d order by zidx ", pBook,pChapter];

FMResultSet *userresults = [userDB executeQuery:query2]; 

3) 问题:与results - zidx 相比,我想修改结果为userresults 的项目的属性(highlight_YN)。

如何修改NSMutableArray 属性?

【问题讨论】:

  • 我在上面的代码中没有看到 NSMutableArray。事实上,我看到了各种各样的问题(比如[items addObject:bible] 中的bible 来自哪里?)。请修改您的问题以清理您的代码并引入 NSMutableArray。
  • @Michael Dautermann 对不起!我遗漏了一些代码。谢谢!!我的问题已编辑。 ^^*

标签: iphone objective-c ios sqlite nsmutablearray


【解决方案1】:

您可以遍历items 数组并搜索对象。

    for ( Book *book in items ) {
        if( book.idx == [userresults intForColumn:@"zidx"] )
        {
            book.highlight_YN = [userresults boolForColumn:@"highlight_YN"];
            break;
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    • 1970-01-01
    • 2012-03-29
    相关资源
    最近更新 更多