删除tableview中的所有本地通知和Cell

时间:2014-07-27 08:15:44

标签: ios objective-c uitableview uilocalnotification

我正在寻找一种方法来删除tableView中的所有localNotifications,并带有一个按钮。 我尝试过使用cancelAllNotifications[array removeAllObject];,但这并没有成功。 我确实有幻灯片删除功能一个一个工作。

Importend要知道每个部分都有2行localNotifications,如下所示。

的cellForRowAtIndexPath:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    int rowIndex = (indexPath.section*2) + indexPath.row;

    // Get list of local notifications
    NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
    UILocalNotification *localNotification = [localNotifications objectAtIndex:rowIndex];

    // Display notification info
    [cell.textLabel setText:[localNotification.alertAction description]];
    cell.textLabel.font = [UIFont systemFontOfSize:14.0];

    return cell;

canEditRowAtIndexPath

    return YES;      
    [self.tableView reloadData];

commitEditingStyle:

if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        // Delete the row from the data source
        int rowIndex = (indexPath.section*2); //get the 2 items of the section
        NSArray *localNotifications = [[UIApplication sharedApplication]  scheduledLocalNotifications];

        UILocalNotification *notify = [localNotifications objectAtIndex:rowIndex];
        [[UIApplication sharedApplication] cancelLocalNotification:notify];
        notify = [localNotifications objectAtIndex:rowIndex+1];
        [[UIApplication sharedApplication] cancelLocalNotification:notify];

        [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
    }

任何人都知道如何做到这一点。

1 个答案:

答案 0 :(得分:1)

从数据源阵列中删除所有对象后,您是否重新加载了表视图?

您应该在按钮的操作

中执行此操作
- (void)clearAllButtonTapped:(UIButton *)clearAllButton
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    [theDataArray removeAllObjects];
    [theTableView reloadData];
}