Pregunta

Tengo el siguiente código en mi aplicación. Su una aplicación para iPad, con cinco mesas en una sola vista denominada montable, tueTable etc. Estas tablas representan lunes a viernes.

En este código me da la fecha y ajuste cada título de la tabla a la fecha de Lunes a Viernes (esta semana). Entonces, si se presiona un botón nextWeek se convierte en realidad y me vuelva a cargar datos de la tabla. Esto significa, entonces, que la semana se incrementa. Ver?

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

Mi problema es que por alguna razón cable sólo aumenta Lunes por siete días a la semana siguiente y ninguno de los otros días se cambian cuando el botón se pulsa alguna idea? Gracias.

¿Fue útil?

Solución

En nextWeekDown método que vuelva a cargar solamente montable - por lo que, naturalmente, otros no lo hacen tablas de recarga. Es necesario para recargar todas las otras tablas, así ...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top