私は、「検索バーと検索ディスプレイコントローラ」とのUITableView(tblFriends)で検索バーを実装しています検索 - NSInvalidArgumentExceptionエラー
これはfilteredFriendsList(friendsListにNSArrayに等しい)の辞書の私にNSArrayです:
{
gender
id
name
picture
}
テーブルは半分だけビューを占有するので、私は(ないtableViewControllerで)のUIViewController、のテーブルビューを持っています。
これはコードです: INTERFACE:私は検索でいくつかの文字を入れて
#import <UIKit/UIKit.h>
#import "ClasseSingleton.h"
#import "FBConnect.h"
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *friendsList;
NSDictionary *friendsDict;
NSMutableArray *filteredFriendsList;
IBOutlet UITableView *tblFriends;
}
@property (nonatomic, retain) NSArray *friendsList;
@property (nonatomic, retain) NSMutableArray *filteredFriendsList;
-(void)getFriends;
@end
実装
#import "ViewController.h"
@implementation ViewController
@synthesize friendsList, filteredFriendsList;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[tblFriends setDelegate:self];
[tblFriends setDataSource:self];
}
- (void)getFriends{
NSLog(@"ENTRATO - getFriends");
//Copy ARRAY in other ARRAY
friendsList = [NSArray arrayWithArray:[ClasseSingleton getFriends]];
filteredFriendsList = [NSArray arrayWithArray:[ClasseSingleton getFriends]];
NSLog(@"getFriends : DESCRIPTION\n\n %@", [friendsList description]);
NSLog(@"Count friendslist: %i", [friendsList count]);
[tblFriends reloadData];
}
// *****TABLE MANAGEMENT***** //
//Nuber of cells
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(@"tabella1");
return [filteredFriendsList count];
}
//Populate the table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat{
static NSString * cellIdentifier = @"cell";
//Set Style cell
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
friendsDict = [filteredFriendsList objectAtIndex:indexPat.row];
//Set CELL TEXT
NSString *cellValue = [friendsDict objectForKey:@"name"];
NSLog(@"TBL %@", cellValue);
[cell.textLabel setText:cellValue];
return cell;
}
// SEARCH IN TABLE
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
[self filterContentForSearchText:searchString scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption{
[self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
// Return YES to cause the search result table view to be reloaded.
return YES;
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)saearchBar {
[self.filteredFriendsList removeAllObjects];
[self.filteredFriendsList addObjectsFromArray: friendsList];
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope{
/*
Update the filtered array based on the search text and scope.
*/
[self.filteredFriendsList removeAllObjects]; // First clear the filtered array.
/*
Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
*/
NSString *cellTitle;
for (cellTitle in friendsList){
// for (cellTitle in [friendsDict objectForKey:@"name"]){
NSComparisonResult result = [cellTitle compare:searchText options:NSCaseInsensitiveSearch range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame){
[filteredFriendsList addObject:cellTitle];
}
}
}
...
@end
毎回このエラーでアプリがクラッシュをバー:
'をNSInvalidArgumentException' 、理由: ' - [__ NSCFDictionary compare:options:range:]:インスタンスに送信された認識できないセレクタ
私はこの問題を解決したいと考えています。このエラーは6日目です。
ありがとうございます。
または '[[ClasseSingleton getFriends] mutableCopyを] ' – warrenm
:(新しいエラーが発生しました:' NSInvalidArgumentException '、理由:' - [__ NSCFDictionary compare:options:range:]: – Byteros
これは全体のエラーではない – yuji