这个问题已经在这里有了答案:
9年前关闭。
得到了以下xcode:
但是,当我尝试在情况1(或空)中放入某些东西时,这给我一个错误吗?
奇怪的问题,因为我不知道什么是 protected 交换机以及如何修复它。有谁有解决方案或线索来解决此问题?奇怪的..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *controller;
switch(indexPath.row) {
case 0:
NSLog(@"0");
//create instance of EKEventStore
EKEventStore *eventStore = [[EKEventStore alloc] init];
//creating instance of EKEvent
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
//setting the appropriate properties of the new event
event.title = @"Woow";
//event.startDate = [[NSDate alloc] init];
NSDateComponents *myDate2 = [[NSDateComponents alloc] init];
[myDate2 setDay:13];
[myDate2 setMonth:12];
[myDate2 setYear:2011];
[myDate2 setHour:00];
[myDate2 setMinute:34];
event.startDate = [[NSCalendar currentCalendar] dateFromComponents:myDate2];
event.endDate = [[NSDate alloc] initWithTimeInterval:3600 sinceDate:event.startDate];
event.location = @"game2";
event.notes = @" game";
event.alarms = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:event.startDate]];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *error;
[eventStore saveEvent:event span:EKSpanThisEvent error:&error];
break;
case 1:
NSLog(@"1");
break;
}
{
self.EKController.title = [self.EKList objectAtIndex:[indexPath row]];
}
}
@end
但是有一个错误:
最佳答案
您应该用{}
大括号包装每个switch语句。例如:
switch (someInt) {
case 0:
{
NSLog(@"Case 0");
}
break;
case 1:
{
NSLog(@"Case 1");
}
break;
}
已经在这里回答了这个问题-When converting a project to use ARC what does "switch case is in protected scope" mean?
关于objective-c - 保护开关中的 shell ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8482678/