質問

アプリに次のコードがあります。 iPadアプリは、Montable、Tuetableなどという名前の1つのビューに5つのテーブルを備えています。これらのテーブルは月曜日から金曜日を表しています。

このコードでは、日付を取得し、各テーブルタイトルを月曜日から金曜日(今週)に設定します。次に、次のウィークを押すと、テーブルデータをリロードします。これは、週が増えることを意味します。見る?

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

私の問題は、いくつかの有線の理由で、それは月曜日に翌週に7日間しか増加し、ボタンがアイデアを押したときに他の日は変更されないということです。ありがとう。

役に立ちましたか?

解決

NextWeekDownメソッドでは、Montableのみをリロードするため、自然に他のテーブルがリロードされません。他のすべてのテーブルもリロードする必要があります...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top