gpt4 book ai didi

ios - 删除 TableView 中的所有本地通知和单元格

转载 作者:行者123 更新时间:2023-11-29 02:47:10 25 4
gpt4 key购买 nike

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

需要知道的是,每个部分都有 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];
}

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

最佳答案

从数据源数组中删除所有对象后,您是否重新加载了 TableView ?

您应该在按钮的操作中执行此操作

- (void)clearAllButtonTapped:(UIButton *)clearAllButton
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];

[theDataArray removeAllObjects];
[theTableView reloadData];
}

关于ios - 删除 TableView 中的所有本地通知和单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24979156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com