如何从xcode中的tableview中删除本地通知

时间:2013-01-08 17:16:02

标签: objective-c ios cocoa-touch uilocalnotification

在我的应用中,我在表格视图中显示本地通知。

以下是代码:

NSArray *notificationArray=[[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
[cell.textLabel setText:notif.alertBody];
[cell.detailTextLabel setText:[notif.fireDate description]];

我想从表格视图中删除所选行,我该怎么办?

2 个答案:

答案 0 :(得分:0)

如果要删除行...从模型中删除。

[yourModelArray removeObjectAtIndex:indexPath.row];

编辑:

重新加载您的表格视图:

[tableView reloadData];

答案 1 :(得分:0)

如果您询问如何删除特定的本地通知,当用户点击特定单元格时,则:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *notificationArray=[[UIApplication sharedApplication] scheduledLocalNotifications];
    UILocalNotification *notificationToCancel= [notificationArray objectAtIndex:indexPath.row];

    [[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];
    [yourTable reloadData];
}