Date Issue

Discussion in 'iOS Programming' started by Josh Kahane, Aug 21, 2010.

  1. macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #1
    Hi

    I have attempted this is many ways but failed consistently, hopefully you guys can help me achieve the what i want to do.

    I am making an iPad app, I will have five tables in a single view and each table will have a date as a header/title in this format, e.g. Monday 20

    These five tables will be monday to friday. This is the bit I cant do. I want to work out the current date and then highlight the table which is today, obviously changes everyday.

    So for example, lets say today is Thursday 9th. Thursday table is highlighted and then is automatically sets the date of the other tables around thursday.

    Think of a school timetable/planner/diary. Monday to friday, each labelled with their dates.

    I hope this makes sense, if not let me know and I will try and visually represent this.
     
  2. macrumors 6502

    Joined:
    Sep 18, 2009
    #2
    You might want to check out NSDate, NSDateComponents and NSDateFormatter. With these, your task should be really simple.
     
  3. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #3
    Well I have been using NSDate and NSDateFormatter like below, but no success:

    Code:
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    	[format setDateFormat:@"EEEE dd"];
    	NSDate *now = [[NSDate alloc] init];
    	NSString *dateString = [format stringFromDate:now];
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Please elaborate.

    I threw your code above into a test project, added an NSLog(), and got:

    2010-08-21 14:42:18.486 Untitled[71611:207] dateString = Saturday 21
     
  5. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #5
    Of course, thats fine, it outputs the current date, but if I have a screen like attached. Now as far as I have gotten is get todays date showing.

    On that screen, lets says its a Thursday, I want the thursday table to be highlighted and then the dates on the other tables are set, so if thursday is the 21st, make friday 22 and wednesday 20 etc

    Hope you understand.
     

    Attached Files:

  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Well, what have you tried already to get the current date highlighted? Also, what have you already tried to do to generate the previous and following dates? NSDate has a instance method that could be used to generate dates that are a given number of seconds relative to the current date.
     
  7. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #7
    Well I have pre named each table as they will always be fixed monday to friday, then checking that against the day I get from the NSDate.

    Also, maybe what your talking about, from that used initWithTimeIntervalSinceNow.

    Anyway I haven't succeeded, if it seems I should have, please let me know why, if not, how else could I achieve this? Thanks.
     
  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Well, I'm still not entirely certain what you've actually tried, so I'm not sure I'm in a position to tell you why you haven't had success yet.

    Also, what happens when the current day is a Saturday or Sunday?
     
  9. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #9
    Nothing is highlighted if its saturday or sunday. This is because they aren't needed.

    I will post back tomorrow with more detail of what i have tried, late here in the UK, thanks for the attempted help so far.
     
  10. macrumors 6502

    Joined:
    Sep 18, 2009
    #10
    I don't know if I understand correctly, but it seems like you really just want to figure what day in the week the current day is. If that's the case, make sure you read this document (linked to in the NSDateFormatter documentation!), specifically the "weekday" field.
     
  11. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
  12. macrumors 6502

    Joined:
    Sep 18, 2009
    #12
  13. macrumors 603

    Joined:
    Aug 9, 2009
    #13
    Post the actual code for what you described.

    We can't debug descriptions.
     
  14. thread starter macrumors 6502

    Joined:
    Aug 29, 2006
    Location:
    Suffolk, UK
    #14
    Who ever said I didn't?! I did, and I know what you say is true, and I do read about it as thoroughly as I can, but when you simply don't understand where to go next, you ask for help, what I have done here.

    I will do, that makes sense.
     
  15. macrumors 6502

    Joined:
    Sep 18, 2009
    #15
    Well, you got 5 tableviews, and I told you how to determine which day in the week a certain day is. From that, you can determine which tableview represents that day. What don't you understand?
     

Share This Page