Domanda

Ho il seguente codice nella mia app. Il suo un app per iPad, con cinque tavoli in un'unica visualizzazione di nome montable, tueTable ecc Queste tabelle rappresentano lunedi al venerdì.

In questo codice ottengo la data e impostare ogni titolo tavolo per la data di lunedi al venerdì (questa settimana). Poi, se si preme un tasto nextWeek diventa TRUE e ricaricare i dati della tabella. Ciò significa quindi che la settimana è aumentato. Vedi?

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

Il mio problema è che per qualche motivo cablata aumenta solo lunedi da sette giorni di tempo per la prossima settimana e nessuno degli altri giorni sono cambiate quando il pulsante viene premuto qualche idea? Grazie.

È stato utile?

Soluzione

Nel metodo nextWeekDown si ricarica solo montable - così naturalmente altri tavoli non lo fanno ricarica. È necessario ricaricare tutti gli altri tavoli e ...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top