Reputation: 751
I have made an iphone application, in which I have put tableview , the data in tableview is added by selecting datetime picker ,whenever we select any date time from picker it will get add into the tableview. Now I want to put all these added value of datetime into an array.
how can I do this. I am searching this concept from last many days. But got no answer. Please if some one know, help me.
Thanks alot.
Upvotes: 0
Views: 214
Reputation: 2937
NSMutableArray
is what you'll want. It provides a method called addObject:
, so you can add these date values to your array with ease.
Edit: You asked for an example, very well. Here's how you can do it and how you should approach such problems in the future:
1) You said you had a UIDatePicker
instance that you wanted to save the date of. So how do we get the date? The first thing you should always do is consult the Apple Developer Documentation, in this case for UIDatePicker. A short read reveals that this class has a date property.
Aah UIDatePicker
, is there anything you can't do?
Now that we have the date we want, you'll want to put it into an NSMutableArray
, as I have suggested. So we do it the same way again - open the Apple Developer Documentation and look up NSMutableArray. That reveals to us that there is in fact a addObject:
method but wait...there's more?? Yep, NSMutableArray
is damn powerful, so have a look through the entire document and see what you can use.
The documentation reveals that we can use addObject:
to add an object to the array, so let's start:
NSMutableArray*myDates = [NSMutableArray array];
Now we've initalised our array. Now let's add an object:
[myDates addObject:[datePicker date]];
Done. We've now added an object. If you want to save this disc at a later stage, use NSMutableArray
's writeToFile:atomically:
method. For more details, read the documentation.
Now don't just go ahead and copy and paste the code. Read Apple's documents on these classes, they are really helpful and will enable you to resolve such problems in the future.
Upvotes: 3
Reputation: 6954
When you add date in table view, add the same date to an array. take an array in .h and then add date to array
[arr addObject:date];
Upvotes: 0