0

刚刚学习 iPhone,我收到以下错误

    [app scheduledLocalNotifications:notification];

uiapplication 没有可见的@interface 声明选择器 schedulelocalnotifications

有人可以帮帮我吗?我确定它很简单,我只是没有意识到,因为这是我的第一个教程

谢谢

-(IBAction)createNotification{

NSLog(@"createNotification");

NSString *dateString = dateTextField.text;
NSString *textString = textTextField.text;

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM-dd-yyyy HH:mm"];
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:-18000]];

NSDate *alertTime = [formatter dateFromString:dateString];

UIApplication* app = [UIApplication sharedApplication];

UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification) {
    notification.fireDate = alertTime;
    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.repeatInterval = 0;
    notification.alertBody = textString;

    [app scheduledLocalNotifications:notification];
    [app presentLocalNotificationNow:notification];

}

}

4

1 回答 1

3

scheduleLocalNotifications 是属性。

此属性包含表示当前计划的本地通知的 UILocalNotification 实例数组。您可以设置或重置阵列中的本地通知以及访问它们。

阅读文档:http: //developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html

更改为以下代码。

NSMutableArray *notifications = [[NSMutableArray alloc] init];
[notifications addObject:notification];
app.scheduledLocalNotifications = notifications;
//Equivalent: [app setScheduledLocalNotifications:notifications];
于 2013-02-09T02:10:25.093 回答