Cell business logic processing (time formatting)

Source: Internet
Author: User

I. Click More button 1. Project Requirements Click the More button to pop a box from the bottom

2. How to pop a box from the bottom?          Two ways:                one with uiactions heet          Another use of uialertcontroller          2.1 uiactionsheet& nbsp         Benefits: No controller required, direct access to           Cons: Method expired, Listener button Click Compare Trouble      & nbsp; Source code://After the discovery of a variable parameter, finally must add niluiactionsheet *sheet = [[Uiactionsheet alloc] Initwithtitle:nil delegate:nil cancelbuttontitle:@ "Cancel" Destructivebuttontitle:nil otherbuttontitles:@ "collection", @ "Report", Nil]; [sheet ShowInView: self];      2.2 using uialertcontroller            Benefits: Ability to monitor button clicks            Cons: Code to write a lot, dependent controller (need controller modal out)           2.3 Use Uialertcontroller to notify the nearest controller to Uialertcontroller   modal           NOTE: Use notifications when the controller is destroyed, be sure to remove notifications        &NBSp  2.4 Why use notifications, do not use proxies?           notifications to deliver messages across levels           agents, It is usually the subordinate to deliver the message           3. How can I get a controller quickly?      Global has a single case uiapplication, With this single example we can get the window with the controller      //later just want to get the controller quickly, take the window root controller     [uiapplication sharedapplication]. keywindow.rootviewcontroller;  two. Time processing  1 for post. Business logic analysis of time processing      1.1 First determine if this is the year's post, if not this year, it will show   2015-08-06 21:10:08 This format       1.2 If it is this year, in judging if it is today, if it is today   in judging whether there are more than one hours, more than one hours to show how many hours ago This format       1.3 if not more than an hour, judging there is no more than 2 minutes more than two minutes to show   how many minutes ago   This format       1.4 If not more than two minutes, just show   This format       1.5 If the time exceeds one day, in judging if there is not more than a day if there is no   show   yesterday 21:10 this format        1.6 If it takes more than a day to show   08-05 21:10:08 this format  2. Because the business logic is very deep, when writing code, easy to confuse, how to deal with?      We can take the pseudo code first, clear the idea, then convert to real code       What is pseudo code: Pseudocode is the combination of Chinese and code written code   pseudo code Instance  //processing time(compared to the current time by post release time)
If (this year) {
if (today) {

if (greater than 1 hours) {

} else if (greater than 2 minutes) {

} else {///Just

}

} else if (yesterday) {

} else {//before yesterday

}

} else{//not this year
} 3. How to get the time difference value?          3.1 First converts the date of the string object to the date format of the Date Object 3.1.1 Gets the NSDateFormatter object, used to nsstreing and nsdate each other to set the date format (date converted to what format)          3.1.3 Converts a string date to a specific format date 4. Judging if this is 4.1 how to judge?          Determine whether the year is the same 4.2 how do I get the date year, or the month, etc.? The Calendar class can be used to get the date component, you can get the year, month day and minute seconds processing date format original code
1  //1. Convert post posting time string to (nsdate) Date Object = = NSDateFormatter2     //nsdateformatter:nsstreing and NSDate3NSDateFormatter *fmt =[[NSDateFormatter alloc] init];4     //Set Format5Fmt.dateformat =@"YYYY-MM-DD HH:mm:ss";6     //Publish Date Object7NSDate *createdate =[FMT dateFromString:item.create_time];8     9     //get Calendar Class objectTen    //Nscalendar *calendar = [Nscalendar Currentcalendar]; One     //Get Date Component A    //nsdatecomponents *cmp = [Calendar Components:nscalendarunithour | Nscalendarunitminute fromdate:createdate todate:[nsdate Date] options:nscalendarwrapcomponents]; -    -NSString *timestr =Item.create_time; the     if([CreateDate isthisyear]) { -         if([CreateDate isthistoday]) { -             -             //Get Date Difference value +             if(Cmp.hour >=1) { -TIMESTR = [NSString stringWithFormat:@"%ld hours ago", Cmp.hour]; +}Else if(Cmp.minute >=2) { ATIMESTR = [NSString stringWithFormat:@"%ld minutes ago", Cmp.minute]; at}Else{//just -Timestr =@"just"; -             }    -}Else if([CreateDate Isthisyesterday]) {//Yesterday -             //Yesterday 21:10 -Fmt.dateformat =@"Yesterday hh:mm"; inTimestr =[FMT stringfromdate:createdate]; -     to}Else{//08-05 21:10:08 before yesterday . +Fmt.dateformat =@"MM-DD HH:mm:ss"; -Timestr =[FMT stringfromdate:createdate]; the         } *     } $  Panax Notoginseng Because judging dates are often used, we take the judging method to the classification of NSDate -   the-(BOOL) isthisyear + { A     //gets the current date object theNSDate *curdate =[NSDate Date]; +     //Get Calendar class -Nscalendar *curcalendar =[Nscalendar Currentcalendar]; $     //Gets the date component (year, month, etc.) of the self code outside the Calendar class that calls this method (that is, createdate) $Nsdatecomponents *selfcmp =[Curcalendar components:nscalendarunityear fromdate:self]; -     //get the current time date component (year, month, etc.) -Nsdatecomponents *curcmp =[Curcalendar components:nscalendarunityear fromdate:curdate]; the     returnCurcmp.year = =selfcmp.year; - }Wuyi  the //Judging whether it's Today --(BOOL) Isthistoday Wu { -     //Get Calendar class AboutNscalendar *curcalendar =[Nscalendar Currentcalendar]; $     return[Curcalendar isdateintoday:self]; - } -  --(BOOL) Isthisyesterday A { +Nscalendar *curcalendar =[Nscalendar Currentcalendar]; the     return[Curcalendar isdateinyesterday:self]; -}

 

Cell business logic processing (time formatting)

Related Article

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.