2012-12-07 2 views
2

alphabatic 위해 테이블보기로 PLIST 데이터를 가져 오는 방법 :나는 PLIST 파일에서 일부 데이터를로드하는 데이 코드를 사용하고

self.title [email protected]"Data"; 
NSString *path = [[NSBundle mainBundle] pathForResource:@"Data"ofType:@"plist"]; 
dict =[NSMutableDictionary dictionaryWithContentsOfFile:path]; 
sortedCountries =[[NSArray alloc]initWithArray:[dict objectForKey:@"Name"]]; 

그리고있는 tableView의 정보를 보여주는 해요 :

cell.textLabel.text = [sortedCountries objectAtIndex:indexPath.row]; 

plist 요소를 올바르게 표시하고 있지만 데이터를 알파벳 순서로 표시해야합니다.

답변

0

변경이 줄이에 대한

sortedCountries =[[NSArray alloc]initWithArray:[dict objectForKey:@"Name"]]; 

:

NSArray *array = [dict objectForKey:@"Name"]; 
sortedCountries = [array sortedArrayUsingSelector:@selector(compare:)]; 
+0

아니면이 방법을 사용할 수 있습니다 http://developer.apple.com/library/ios/documentation/Cocoa/Reference /Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingComparator : – dasdom

관련 문제