Wednesday, October 9, 2013

iOS Sorted Array From pList

- (void)viewDidLoad
    [super viewDidLoad];
    NSString *pathname = [[NSBundle mainBundle]pathForResource:@"myTableList" ofType:@"plist"];
    NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:pathname];
    self.Array = array;

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"key" ascending:YES];
    NSArray *sortDescriptorArray = [NSArray arrayWithObject:sortDescriptor];
    NSArray *sortedArray = [self.Array sortedArrayUsingDescriptors:sortDescriptorArray];
    [self.Array removeAllObjects];
     self.Array = (NSMutableArray *)sortedArray;

No comments: