如何修改NSMutableArray属性?

时间:2011-11-21 04:56:02

标签: iphone objective-c ios sqlite nsmutablearray

我使用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)问题:我想修改highlight_YNuserresults - results相比的项目的属性(zidx)。

如何修改NSMutableArray属性?

1 个答案:

答案 0 :(得分:1)

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

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