尝试取消UILocalNotification时出错

时间:2014-11-14 14:25:06

标签: ios objective-c uitableview uilocalnotification

我从我的UILocalNotification子类计划UITableViewCell

UILocalNotification *notification = [[UILocalNotification alloc] init];

[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:event.destinationTime]];

[notification setAlertBody:title];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];

[[UIApplication sharedApplication] scheduleLocalNotification:notification];
self.eventNotification = notification; // assigning to class property

我在删除单元格时尝试取消通知:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    CustomCell *cell = (CustomCell *) [self.tableView cellForRowAtIndexPath:indexPath];

    [[UIApplication sharedApplication] cancelLocalNotification:cell.eventNotification];
}

但是当我运行时,删除单元格时出现以下错误:

'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

有什么问题?或者我做错了吗?谢谢!

1 个答案:

答案 0 :(得分:0)

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

首先从数据模型中删除您要删除的项目

[_arrayOfData removeObjectAtIndexPath:indexPath.row];

然后从表View

中删除相应的行
NSArray *indexPaths = @[indexPath];
[tableView deleteRowsAtIndexPath:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];

[[UIApplication sharedApplication] cancelLocalNotification:cell.eventNotification];

}