سؤال

لدي الرمز التالي في تطبيقي. إنه تطبيق iPad ، مع خمسة جداول في عرض واحد يسمى Montable ، Tuetable وما إلى ذلك. تمثل هذه الجداول من الاثنين إلى الجمعة.

في هذا الرمز ، أحصل على التاريخ وأعين كل عنوان جدول إلى التاريخ من الاثنين إلى الجمعة (هذا الأسبوع). ثم إذا ضغطت على زر في الأسبوع التالي ، فأصبح صحيحًا وأعيد تحميل بيانات الجدول. هذا يعني ثم زيادة الأسبوع. نرى؟

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

مشكلتي هي أنه لسبب سلكي يزداد يوم الاثنين فقط بحلول سبعة أيام حتى الأسبوع المقبل ولم يتم تغيير أي من الأيام الأخرى عندما يتم الضغط على الزر أي أفكار؟ شكرًا.

هل كانت مفيدة؟

المحلول

في طريقة NextWeekdown ، تقوم بإعادة تحميل Montable فقط - لذلك من الطبيعي أن لا يتم إعادة تحميل الطاولات الأخرى. تحتاج إلى إعادة تحميل جميع الطاولات الأخرى أيضًا ...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top