首先,我是新來的,所以請原諒我最簡單的問題。
我正在嘗試查看數據並對其進行過濾,這很常見。
所以我使用不同的教程。首先,我從我的SQLite數據庫加載數據,
然後我使用自定義單元格教程和自定義我的單元格。但是我被困在UISearchBar中。
我遵循的教程使用NSArray來填充在代碼隱藏中聲明的表。由於我的SQLite方法從數據庫獲取數據到一個數組,我想如果我將這個數組複製到過濾方法中的數組,那會起作用。
但它沒有。
下面是一些代碼與解釋:上述
由SQLite查詢加載的UISearchBar問題
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if ([searchText length] == 0) {
[displayItems removeAllObjects];
[displayItems addObjectsFromArray:allItems];
} else {
[displayItems removeAllObjects];
for (NSString *string in allItems) {
NSRange r = [string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (r.location != NSNotFound) {
[displayItems addObject:string];
}
}
}
[tableViewScreen reloadData];
}
碼是用於過濾和我試圖我用於填充表格allItems陣列這樣的陣列複製:
MyProjectAppDelegate *appDelegate = (MyProjectAppDelegate *)[[UIApplication sharedApplication] delegate];
allItems = appDelegate.mySqliteArray;
或者這樣:
allItems = [[NSArray alloc] initWithArray:appDelegate.mySqliteArray];
但他們都沒有工作。
我想再次指出我的問題
我有一個方法將數據獲取到AppDelegate類中的數組中,並且在我的TableView類中我想將該數組複製到另一箇中。
P.S. mySqliteArray是可變數組,allItems數組不是。
而且,我的單元格是由自定義單元類創建的,每行中有2個標籤。