我有這樣的XML這是我在UITableView中顯示:篩選的UITableView從XML源
<result>
<trip duration="03:30">
<takeoff date="2010-06-19" time="18:40" city="Moscow"/>
<landing date="2010-06-19" time="20:10" city="Novgorod"/>
<flight carrier="Rossiya" number="8395" eq="320"/>
<price>13429.00</price>
</trip>
<trip duration="03:40">
<takeoff date="2010-06-19" time="09:20" city="Omsk"/>
<landing date="2010-06-19" time="11:15" city="Paris"/>
<flight carrier="AirFrance" number="1145" eq="320"/>
<price>13229.00</price>
</trip>
<trip duration="03:50">
<takeoff date="2010-06-19" time="07:20" city="Omsk"/>
<landing date="2010-06-19" time="14:15" city="Barcelona"/>
<flight carrier="AirFrance" number="1100" eq="320"/>
<price>13329.00</price>
</trip>
</result>
我使用這段代碼保存它:
if ([elementname isEqualToString:@"trip"]) {
currentTweet = [Tweet alloc];
isStatus = YES;
flightTime = [attributeDict objectForKey:@"duration"];
currentTweet.flightDuration = [NSString stringWithFormat:@"Flight duration is: %@", flightTime];
}
if([elementname isEqualToString:@"takeoff"]) {
takeoffPlace = [attributeDict objectForKey:@"city"];
}
if ([elementname isEqualToString:@"landing"]) {
landingPlace = [attributeDict objectForKey:@"city"];
currentTweet.content = [NSString stringWithFormat:@"%@ - %@", takeoffPlace, landingPlace];
}
if ([elementname isEqualToString:@"takeoff"]) {
takeoffDate = [attributeDict objectForKey:@"date"];
takeoffTime = [attributeDict objectForKey:@"time"];
currentTweet.takeOffAll = [NSString stringWithFormat:@"Take off date %@. Take off time %@", takeoffDate, takeoffTime];
}
if ([elementname isEqualToString:@"landing"]) {
landingDate = [attributeDict objectForKey:@"date"];
landingTime = [attributeDict objectForKey:@"time"];
currentTweet.landingAll = [NSString stringWithFormat:@"Landing date %@. Landing time %@", landingDate, landingTime];
}
if ([elementname isEqualToString:@"flight"]) {
companyName = [attributeDict objectForKey:@"carrier"];
companyNumber = [attributeDict objectForKey:@"number"];
eqStuff = [attributeDict objectForKey:@"eq"];
currentTweet.companyInfo = [NSString stringWithFormat:@"Carrier: %@ Flight number: %@ Eq: %@", companyName, companyNumber, eqStuff];
}
我需要2我的TableView排序參數:
的
<trip duration="03:50">
時間的
<price>
我不知道我是否使用了正確的結構 - 基本上所有的數據分配到一個獨立的數據類,然後分配給UITableView的細胞內UILabels NSString的。
按時間和價格排序數據的最佳方法是什麼?關於如何重新格式化代碼的任何想法?
P.S.我使用SegmentedControl重新加載TableView並對其進行相應的排序。
感謝您的詳細解釋。我會嘗試一下並報告。 –
@SergiusGee我意識到我是按日期和時間排序的,而您希望按持續時間和價格排序,所以我相應地修改了我的答案。 – Rob