views:

41

answers:

1

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.

A: 

In nextWeekDown method you reload only monTable - so naturally other tables don't reload. You need to reload all other tables as well...

Vladimir
You have gone a made me look stupid now... :) I vow never to ask a question like this late at night when Im half awake ever again. Guess its also part of learning to be efficient in reading back over my own code, I'll get there one day.
Josh Kahane
Just a follow up to this question. I have it so that when the button is pressed nextWeek is TRUE, meaning of course the tables are reloaded seven days ahead. But for my life I can't get nextWeek to = FALSE and be able to press the button again.
Josh Kahane
Dont worry have that fixed! However another issue! When I press next week button it keeps going through the weeks but when it reaches the end of september it goes back to august.
Josh Kahane