2014-11-14 2 views
0

я запланировать 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]'

В чем проблема? Или я делаю это неправильно? Благодаря!

+0

Тестируете в iOS8 + OR iOS7 и ниже? –

+0

@YogeshSuthar iOS 8 – Eilon

+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]; 

}

Смежные вопросы