我正在使用以下代码在iPhone的日历中创建事件;

        EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
        event.title     = @"DHSB Assignment: %@", Assignment1.text;

        event.startDate = [[NSDate alloc] init];
        event.endDate   = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];

        [event setCalendar:[eventStore defaultCalendarForNewEvents]];
        NSError *err;
        [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
        [EKEventStore release];

        NSLog(@"Successfully added '%@' to the calendar", Assignment1.text);

为什么要保存名称为“DHSB分配:%@”而不是“DHSB分配:示例文本”的事件?

谢谢。

最佳答案

event.title = [NSString stringWithFormat:@"DHSB Assignment: %@", Assignment1.text];

您当前的代码等效于
[event setTitle:@"DHSB Assignment: %@"];
[Assignment1 text];

…这是有效的,因此即使它没有执行您想要的操作,它也可以编译并正常运行。

10-04 23:38