2012-11-07 30 views
0

對象我有一個類,有一些objects(標題,價格,修飾符),而且我有這個類的NSArrayobjects如何使用searchDisplayController和

我把這個NSArray加載到UITableView。我怎樣才能使用searchDisplayController? 我無法理解..數組只有地址(對我的類中的對象)以及如何通過謂詞對它進行排序?

回答

0

我可以用一個例子解釋

我們考慮我的代碼是像下面

沒有NSPredicate

NSMutableArray *oldSkoolFiltered = [[NSMutableArray alloc] init]; 
for (Book *book in bookshelf) { 
    if ([book.publisher isEqualToString:@"Apress"]) { 
     [oldSkoolFiltered addObject:book]; 
    } 
} 

應用NSPredicate

NSPredicate *predicate = 
    [NSPredicate predicateWithFormat:@"publisher == %@", @"Apress" ]; 
NSArray *filtered = [bookshelf filteredArrayUsingPredicate:predicate]; 
+0

去這個例子將真正幫助你http://www.apptite.be/blog/ios/3-搜索功能於表樣本-iphone應用觸點教程/ –

0

我想你已經忘記了將數組類型轉換爲類名稱。 嘗試做這樣的

cell.textLabel.text=((ClassName *)[arrOfObjects objectAtIndex:indexPath.row]).Title; 

並斷言我會建議你通過這個example

相關問題