Select a date range and determine whether the selected start date and end date are correct.
// Convert the string into a date for the next comparison
-(Nsdate *) stringtodate: (nsstring *) String
{
Nsdateformatter * dateformatter = [[nsdateformatter alloc] init];
[Dateformatter setdateformat: @ "yyyy-mm-dd"];
Nsdate * Date = [dateformatter datefromstring: String];
// Nslog (@ "date % @", date );
[Dateformatter release];
Return date;
}
// ++ ++ //
// Click the search button.
-(Void) searchmessage
{
// ======================== Hide the time selector that is not hidden first ====================== ======== //
[Uiview beginanimations: Nil context: Nil];
[Uiview setanimationduration: 0.3];
// Hide the toolbar
Cgrect toolbarframe = self. navigationcontroller. toolbar. frame;
Toolbarframe. Origin. Y =
Self. View. bounds. Size. height + 65;
Self. navigationcontroller. toolbar. Frame = toolbarframe;
// Hide the finish button
Uibarbuttonitem * spacebutton = [[uibarbuttonitem alloc]
Initwithbarbuttonsystemitem: uibarbuttonsystemitemfixedspace
Target: Nil action: Nil] autorelease];
[Self settoolbaritems: [nsarray arraywithobject: spacebutton] animated: Yes];
// Hide the date Selector
Datepicker _. Frame = toolbarframe;
[Uiview commitanimations];
// ================================================ ==================================== //
If ([begindatetextfield _. Text length] & [enddatetextfield _. Text length])
{
*************************//
Nsdate * begindate = [self stringtodate: begindatetextfield _. Text];
Nsdate * enddate = [self stringtodate: enddatetextfield _. Text];
// If the start date is earlier than the end date, the next step is executed. Otherwise, a warning box is displayed.
If (nsorderedascending = [begindate compare: enddate])
{
// Execute the next step
............
}
Else // Date range error
{
Uialertview * erroralert = [[uialertview alloc] initwithtitle: @ "incorrect date range" message: @ "Please select the correct date range" delegate: Self cancelbuttontitle: @ "OK" otherbuttontitles: nil, nil];
[Erroralert show];
[Erroralert release];
}
//************************************** *****//
}
Else // Date range not selected, with an unselected date
{
Uialertview * erroralert = [[uialertview alloc] initwithtitle: @ "Date range not selected" message: @ "select date range" delegate: Self cancelbuttontitle: @ "OK" otherbuttontitles: nil, nil];
[Erroralert show];
[Erroralert release];
}
}