2012-01-28 15 views
2

カレンダーアプリケーション用のカスタムカレンダーを作成しましたが、このコードを実行する手助けをしてくれれば幸いです。 は、例えば2日目、4、13、24カスタムカレンダーテーブルiOSを作成する際に問題が発生する

- (NSString *) showPersianDay { 

    NSCalendar *persCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSPersianCalendar];  
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    NSLocale *IRLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"fa_IR"]; 
    [dateFormatter setLocale:IRLocal]; 
    [dateFormatter setCalendar:persCalendar]; 

    offsetComponents = [[NSDateComponents alloc] init]; 
    offsetComponents.day = _dayNumber; 

    NSDate *nextDate = [persCalendar dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0]; 

    [dateFormatter setDateFormat:@"d"]; 
    NSString *currDay = [dateFormatter stringFromDate:nextDate]; 

    [NSString stringWithFormat:@"%@",currDay]; 

    [persCalendar release]; 
    [dateFormatter release]; 

    return currDay; 
} 

は、私はこの数にすると、ユーザータップは私の日は、番号に従って

を変更する必要があり、月の日数を示して月のカスタムテーブルを作成しました例えば

enter image description here

今日は1月4日である - 私はのようないくつかの方法を使用する必要はありませんユーザータップ1月6日私の日付は1月6日

に変更する必要がある場合:day.text = @"6"か何か.. ..私はねdは本当のDATEを返します。特定の日を表示するようにコードを変更するにはどうすればよいですか? ありがとうございます。

+1

タップが発生したときの通知方法 – Allen

答えて

1

多分、クラスにNSDictionaryを複数のキーで返すようにする必要があります。 1つのキーには曜日の文字列値を含めることができ、もう1つのキーには日付オブジェクトを含めることができます。

- (NSDictionary *) showPersianDay { 

    NSCalendar *persCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSPersianCalendar];  
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    NSLocale *IRLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"fa_IR"]; 
    [dateFormatter setLocale:IRLocal]; 
    [dateFormatter setCalendar:persCalendar]; 

    offsetComponents = [[NSDateComponents alloc] init]; 
    offsetComponents.day = _dayNumber; 

    NSDate *nextDate = [persCalendar dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0]; 

    [dateFormatter setDateFormat:@"d"]; 
    NSString *currDay = [dateFormatter stringFromDate:nextDate]; 

    [NSString stringWithFormat:@"%@",currDay]; 
    NSDictionary *results = [NSDictionary dictionaryWithObjectsAndKeys:currDay,@"dateString",nextDate,@"DateObj" nil]; 

    return results; 
} 

次に、dateStringを表示し、カレンダーセルにDateObjをキャッシュすることができます。うまくいけば、これはあなたの質問を解決します。

+0

私はあなたの質問に答えた場合に記入してください。ありがとう:) – MobileOverlord

関連する問題