簡體   English   中英

嘗試取消UILocalNotification時出錯

[英]Error when attempting to cancel a UILocalNotification

我從我的UITableViewCell子類安排了一個UILocalNotification

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]'

問題是什么? 還是我做錯了? 謝謝!

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

首先從數據模型中刪除您要刪除的項目

[_arrayOfData removeObjectAtIndexPath:indexPath.row];

然后從表視圖中刪除相應的行

NSArray *indexPaths = @[indexPath];
[tableView deleteRowsAtIndexPath:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM