2011-01-06 91 views
1

如何在UITableView中顯示xml解析數據按字母順序排列。以字母順序顯示數據iphone

+0

使用排序描述符。 – BoltClock 2011-01-06 06:12:04

+0

yeap我使用排序描述先生......其工作正常我的NSMutableArray ..靜態數據...當我分析XML數據。我的應用程序崩潰。 – 2011-01-06 06:31:57

回答

5

爲了在此處顯示/安排你的數據在一個陣列中,你必須使用NSSortDescriptor

字母,你必須使這個NSSortDescriptor類的對象,並給數據你從XML獲取

NSSortDescriptor *itemXml = [[NSSortDescriptor alloc] initWithKey:@"itemName" ascending:YES]; 

現在假設你有一個數組sortDescriptors

NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:itemXml,nil]; 


[yourArray sortUsingDescriptors:sortDescriptors]; 

現在請yourArray你UITableView委託方法......你會得到表

4
NSSortDescriptor *sorter; 

sorter = [[NSSortDescriptor alloc]initWithKey:@"Category" ascending:YES]; 

NSArray *sortDescriptors = [NSArray arrayWithObject:sorter]; 

[categoryListArray sortUsingDescriptors:sortDescriptors]; 

[sorter release]; 

嘗試這個

0

排序的數據其實有很多不同的方式來排序數組。

排序描述符只是一個例子。

其他的是對Mac OS 10.6和iOS 4.0,sortedArrayWithOptions:usingComparator進行sortedArrayUsingComparator,sortedArrayUsingFunction:context,sortedArrayUsingSelector和new。

這些是返回排序數組的NSArray方法。

NSMutableArray在「就地」對可變數組進行排序的方法中也有變化。