我有这样的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