Select a date range and determine whether the selected start date and end date are correct.

Source: Internet
Author: User

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];

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.