1

私は iOS 開発にかなり慣れていないので、簡単な質問がありました。UITableView's練習用にいくつかのサンプル アプリケーション開発で使用してきましたが、データソースがNSArray. この背後にある理由は、現在のUITableViewCellインデックスをデータソースの適切なインデックスにマップできるようにするためです。

Objective-Cというわけで、やっと勉強やiOS開発を始めた頃に作りたかった企画に取り掛かる事が出来ました。日々の予定を一覧表示するカレンダーアプリUITableView。私の質問は、私は のEKCalendarオブジェクトからイベントにアクセスしており、1 日ごとにさまざまなイベントを持つ複数のカレンダーを持っているため、データソースEKEventStoreでどのように設定しますか? UITableView's私はもともと の を作成したばかりNSArrayでしたNSDates現在の日から 3 年間さかのぼり、現在の日から 3 年間前にまたがる場合、テーブル ビューのインデックスをデータソースとしてこれにマップできます。ユーザーが 3 年以上先に進む必要がある場合はどうなるでしょうか。これを行うには、より効率的なマナーまたはより良いアプローチがあると思います。

- (id)init {
    self = [super init];

    if (self) {
        //Get calendar access from the user.
        [self initCalendars];

        DateUtility *dateUtility = [[DateUtility alloc] init];

        NSMutableArray *dates = [[NSMutableArray alloc] init];

        //Build array of NSDates for sharing with the View Controller
        //This seems like the incorrect way to do this...
        //Backwards three years
        for (int date = -(365*3); date < 0; date++) {
            [dates addObject:[dateUtility adjustDate:[NSDate date] byNumberOfDays:date]];
        }

        //Forward three years
        for (int date = 0; date < (365*3); date++) {
            [dates addObject:[dateUtility adjustDate:[NSDate date] byNumberOfDays:date]];
        }
    }

    return self;
}

- (void)initCalendars {
    //respondsToSelector indicates iOS 6 support.
    if ([self.eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
        //Request access to user calendar
        [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
            if (granted) {
                NSLog(@"iOS 6+ Access to EventStore calendar granted.");
            } else {
                NSLog(@"Access to EventStore calendar denied.");
            }
        }];
    } else { //iOS 5.x and lower support if Selector is not supported
        NSLog(@"iOS 5.x < Access to EventStore calendar granted.");
    }

    //Store a reference to all of the users calendars on the system.
    self.calendars = [self.eventStore calendarsForEntityType:EKEntityTypeEvent];

    [self.eventStore reset];
}

これは、すべてのコードの動作を確認したい場合のadjustDate メソッドです。

- (NSDate *)adjustDate:(NSDate *)date byNumberOfDays:(NSUInteger)numberOfDays {
    NSDateComponents *components = [[NSDateComponents alloc] init];
    components.day = numberOfDays;

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

    return [calendar dateByAddingComponents:components toDate:date options:0];
}

EKCalendarsイベント ストア内の複数のデータを単一のデータ ソースとして使用するために使用する最適な設計パターンは何UITableViewですか? 特定の日に開催されるイベントの数に関係なく、または使用されているカレンダーに関係なく、カレンダーの日付をデータソースとしてどのようにセットアップしますか?

助けてくれてありがとう!

4

1 に答える 1