4
目前我正在循环查看所有计划的本地通知,以便根据userInfo字典对象中的值查找“匹配”。当我设置了30多个本地通知时,这看起来非常缓慢。有没有一种方法可以访问单个本地通知而无需遍历数组?在没有for循环的情况下在scheduledLocalNotifications数组中找到UILocalNotification?
以下是我有:
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *row = nil;
for (row in notificationArray) {
NSDictionary *userInfo = row.userInfo;
NSString *identifier = [userInfo valueForKey:@"movieTitle"];
NSDate *currentAlarmDateTime = row.fireDate;
if([identifier isEqualToString:myLookUpName]) {
NSLog(@"Found a match!");
}
}
下面是我想:
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *row = " The row in notificationArray where [userInfo valueForKey:@"movieTitle"]=myLookUpName" ;
你能向我解释什么是在试块码怎么回事?我尝试将它“复制并粘贴到”我的代码中,但它会产生一个错误:将'id(^)(id,NSUInteger,BOOL *)'发送到类型为'BOOL(^)的参数的不兼容块指针类型(id, NSUInteger,BOOL *)' – Eric 2012-04-16 01:40:08
@Eric:不知道你为什么会得到这个错误。 http://www.fieryrobot.com/blog/2010/06/20/being-a-blockhead/可能有助于确定问题。 – 2012-04-16 13:46:32
在这里真正来临,但对于谁在这个伟大的答案绊倒,但由代码中的错字抛出的任何其他人,试试这个: ''' UILocalNotification * row = [[notificationArray objectsAtIndexes:[notificationArray indexesOfObjectsPassingTest:^ (id obj,NSUInteger idx,BOOL * stop){ return [[[obj userInfo] valueForKey:@“movieTitle”] isEqualToString:myLookUpName]; }]] objectAtIndex:0]; ''' – 2015-12-02 10:28:50