Unable to alter UIButton in EKEvent code
I'm trying to create a button that when pressed creates a calendar event,
and changes the title of said button to "Event Created" or perhaps creates
an an AlertView to the same effect. This is my code so far:
- (IBAction)AddToCal:(id)sender {
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL
granted, NSError *error) {
if (!granted) {
//Code to handle not-granted
}
else {
//Code to create event
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err;
[store saveEvent:event span:EKSpanThisEvent error:&err];
[[NSUserDefaults standardUserDefaults] setBool:true
forKey:[NSString stringWithFormat:@"%@Sub", PrevDest] ];
[[NSUserDefaults standardUserDefaults] synchronize];
[AddReminder setTitle: [NSString
stringWithFormat:@"Subscribed!"] forState:
UIControlStateNormal];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Event Added!"
message:@""
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}];
//Where I tested different placement of the code
}
Now this creates the event all fine and dandy, but it doesn't create an
AlertView or change the title as confirmation, and even more, it makes my
app freeze and become unresponsive to touches... until, that is, I press
the home button, then reopen the app, at which point the title changes,
and my AlertView pops up.
I've tried putting the title changing code at the marked location, which
makes it work, but this of course is outside the if(!granted), and would
therefore cause the button to change no matter what. And even putting the
code there causes the same freezing phenomena.
I really have no clue whats up with this. Has anyone on here had the same
problem?
No comments:
Post a Comment