2
Objective-C newbie 여기,어떻게하면 plist 데이터를 한 번에 정렬하고 필터링 할 수 있습니까?
plist에서 데이터를 가져 와서 필터링 한 다음 정렬하려고합니다. 다른 페이지에서 아래의 정렬 방법을 사용하면 정상적으로 작동합니다. 내가 라인에이 경고를받을 수 있나요
는 다음과 같이 언급 호환되지 않는 포인터 유형 'NSArray *'
에서 'NSMutableArray *'
에 할당 I이 오류 얻을 :
2011-12-19 11:16:39.142 ATCScontacts[2511:707] -[__NSArrayI sortUsingDescriptors:]: unrecognized selector sent to instance 0x159cf0
2011-12-19 11:16:39.149 ATCScontacts[2511:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI sortUsingDescriptors:]: unrecognized selector sent to instance 0x159cf0'
인터페이스 파일 :
#import <UIKit/UIKit.h>
@class customDetailViewController;
@interface contactsViewController : UITableViewController
{
NSMutableArray *contacts_;
}
@property (nonatomic, retain) NSMutableArray* contacts;
을 구현 파일 :
- (void)viewDidLoad
{
[super viewDidLoad];
//Load plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"contactD" ofType:@"plist"];
contacts_ = [[NSMutableArray alloc]initWithContentsOfFile:path];
//Filter array using predicates
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", "ABC", selection];
//ALERT DISPLAYS HERE:
contacts_ = [contacts_ filteredArrayUsingPredicate:predicate];
//Apply sorting on load
NSSortDescriptor *contactSorter = [[NSSortDescriptor alloc] initWithKey:LAST_KEY ascending:YES selector:@selector(caseInsensitiveCompare:)];
[contacts_ sortUsingDescriptors:[NSArray arrayWithObject:contactSorter]];
[contactSorter release];
}
도움말 도움말!
감사합니다. 여전히 당신을
[[contacts_ filteredArrayUsingPredicate:predicate] mutableCopy];
을하지만 : 브라이언
그랬습니다! 매우 감사합니다! – user992016