2011-11-21 70 views
0

我使用2個sqlite數據庫文件。我該如何修改NSMutableArray屬性?

1)從sqlite數據庫中填充項目。

@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-源碼分貝選擇條目。

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)問:我想用userresults結果與results相比,修改項目的屬性(highlight_YN) - zidx

如何修改NSMutableArray屬性?

+0

我沒有在你的代碼中看到NSMutableArray。事實上,我看到了各種各樣的問題(比如'[addObject:bible]'中的'聖經'來自哪裏?)。請修改您的問題以清理您的代碼並引入一個NSMutableArray。 –

+0

@Michael Dautermann對不起!我遺漏了一些代碼。謝謝!!我的問題被編輯。 ^^ * – hyekyung

回答

1

您可以循環訪問items數組並搜索該對象。

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

謝謝!你的回答非常有幫助。^__^ – hyekyung

+0

不客氣 – Ilanchezhian