Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Josh Kahane

macrumors 6502
Original poster
Aug 29, 2006
439
1
Suffolk, UK
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.
 
You might want to check out NSDate, NSDateComponents and NSDateFormatter. With these, your task should be really simple.
 
You might want to check out NSDate, NSDateComponents and NSDateFormatter. With these, your task should be really simple.

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

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.
 

Attachments

  • Screen shot 2010-08-21 at 21.46.56.png
    Screen shot 2010-08-21 at 21.46.56.png
    57.3 KB · Views: 108
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
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.
 
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.

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.
 
Anyway I haven't succeeded, if it seems I should have, please let me know why, if not, how else could I achieve this?
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?
 
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?

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

Post the actual code for what you described.

We can't debug descriptions.
 
Why don't you consider what I wrote in my previous post? Copy & paste without understanding won't get you anywhere (95% of iOS devs don't understand that).

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.

Post the actual code for what you described.

We can't debug descriptions.

I will do, that makes sense.
 
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.

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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.