7

私はObjective Cのブロックにかなり慣れていません。ドキュメントを読んだことがあり、それらについてかなり基本的な理解があります。

なぜこれがうまくいかないのですか?これは、カレンダーへのアクセスをリクエストするためのフレームワーク コールバックです。引数としてブロックを取ります。私がやりたいことは、ブロックに UIAlertView を割り当てて表示することだけですが、表示しようとするとクラッシュします。

これがばかげた質問ではないことを願っています...ブロックを使用したネット上のすべての紹介例は、カウンターを使用した簡単な例を示しているだけです。

//Request access
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

            if (granted == FALSE) {
                UIAlertView *myAlert = [[[UIAlertView alloc]initWithTitle:@"Calendar Access Denied"
                                                                          message:@"<InfoText>"
                                                                         delegate:nil
                                                                cancelButtonTitle:@"OK"
                                                                otherButtonTitles:nil] autorelease];
                [myAlert show];
            }
            else {
                [self addToCalendar];
            }
        }];
4

1 に答える 1

24

やってみました?

if (granted == FALSE)
{
    dispatch_async(dispatch_get_main_queue(), ^{
       UIAlertView *myAlert = [[[UIAlertView alloc]initWithTitle:@"Calendar Access Denied"
                                                         message:@ <InfoText>"
                                                        delegate:nil
                                               cancelButtonTitle:@"OK"
                                               otherButtonTitles:nil] autorelease];
       [myAlert show];
    });
}

これにより、メインスレッドでコールバックが行われ、ブロックとUIKitを混在させるのに役立ちます

于 2012-10-03T00:41:18.463 に答える