Hi, I have the following code in my app. Its an iPad app, with five tables in a single view named monTable, tueTable etc. These tables represent monday to friday.
In this code I get the date and set each table title to the date monday to friday (this week). Then if I press a button nextWeek becomes TRUE and I reload table data. This then means that the week is increased. See?
-(IBAction)nextWeekDown{
nextWeek = TRUE;
[monTable reloadData];
}
- (NSString*) tableView:(UITableView *)tableView titleForHeaderInSection:(int)section{
curDate = [NSDate date]; // Get current date
calendar = [NSCalendar currentCalendar];// Init calendar
comps = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSWeekCalendarUnit|NSWeekdayCalendarUnit fromDate:curDate]; // Get necessary date components
// Week days change from 1 to 7, Sunday is the 1st, Saturday - the last one.
if (tableView == monTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:2];
}
}
if (tableView == tueTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:3];
}
}
if (tableView == wedTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:4];
}
}
if (tableView == thuTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:5];
}
}
if (tableView == friTable){
if(nextWeek == TRUE){
[comps setHour:168];
NSDate *date = [calendar dateByAddingComponents:comps toDate:curDate options:0];
}
else{
[comps setWeekday:6];
}
}
NSDate *tDate = [calendar dateFromComponents:comps];
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"EEE, MMM d"];
return [formatter stringFromDate:tDate];
}
My issue is that for some wired reason it only increases monday by seven days to the next week and none of the other days are changed when the button is pressed any ideas? Thanks.