1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Date Issue

Discussion in 'iPhone/iPad Programming' started by Josh Kahane, Aug 21, 2010.

  1. macrumors 6502


    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

    You might want to check out NSDate, NSDateComponents and NSDateFormatter. With these, your task should be really simple.
  3. macrumors 6502

    Well I have been using NSDate and NSDateFormatter like below, but no success:

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


    Staff Member

    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. macrumors 6502

    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


    Staff Member

    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. macrumors 6502

    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


    Staff Member

    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. macrumors 6502

    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

    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. macrumors 6502

  12. macrumors 6502

  13. macrumors 603

    Post the actual code for what you described.

    We can't debug descriptions.
  14. macrumors 6502

    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

    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