简体   繁体   English

将所有NSDate对象转换为NSString对象的数组

[英]convert all NSDate objects into array to NSString objects

i have an xml file having list of .Every date has a list of events.i want to display the date in uisegmentation control.when the user click the date in uisegmentation i am displaying the list of event for the date shown below.My xml structure is 我有一个列表为xml的xml文件。每个日期都有一个事件列表。我想在uisegmentation控件中显示日期。当用户单击uisegmentation中的日期时,我正在为以下所示的日期显示事件列表。结构是

<event>
</title>
</desc>
<date>01/02/2012</date>
</event>

I done everything the problem is.I am getting all dates and remove duplicates 我已经解决了所有问题,正在获取所有日期并删除重复项

[ datearray valueForKeyPath:@"@distinctUnionOfObjects.date"]

and i sort the date using 我使用排序日期

sortedArrayUsingSelector:@selector(compare:)

Now my array has a list of nsdate object .I want to convert nsdate object to nsstring.. 现在我的数组有一个nsdate对象的列表。我想将nsdate对象转换为nsstring。

I tried for loop and nsdateformatter to check every index and change into string and add into new array..it's a lengthy process...is it correct or any other better option 我尝试使用循环和nsdateformatter检查每个索引并更改为字符串并添加到新数组中。这是一个漫长的过程...它是正确的还是任何其他更好的选择

Finally 最后

 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:datearray]

If I've understood your question right, you want to convert all the NSDate objects in your mutable array to NSString objects. 如果我正确理解了您的问题,则希望将可变数组中的所有NSDate对象都转换为NSString对象。

NSArray *arrayOfStrings=[dateArray valueForKey:@"description"];

valueForKey: will be called on all objects of date array and the results will be stored in the new array. valueForKey:将在日期数组的所有对象上调用,结果将存储在新数组中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM