如何从xcode中的tableview中删除本地通知
Posted
技术标签:
【中文标题】如何从xcode中的tableview中删除本地通知【英文标题】:How to delete local notifications from tableview in xcode 【发布时间】:2013-01-08 17:16:02 【问题描述】:在我的应用中,我在表格视图中显示本地通知。
代码如下:
NSArray *notificationArray=[[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
[cell.textLabel setText:notif.alertBody];
[cell.detailTextLabel setText:[notif.fireDate description]];
我想从表格视图中删除选定的行,我该怎么做?
【问题讨论】:
请考虑一下您标记的内容与xcode
IDE 无关。
【参考方案1】:
如果您询问如何删除特定的本地通知,当用户点击特定单元格时:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
NSArray *notificationArray=[[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notificationToCancel= [notificationArray objectAtIndex:indexPath.row];
[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];
[yourTable reloadData];
【讨论】:
@ArulKumar:意思是,如果您需要删除通知,您可以这样做。如果您只需要删除行,请使用 anoop 的答案。有什么问题?【参考方案2】:如果要删除行...从模型中删除。
[yourModelArray removeObjectAtIndex:indexPath.row];
编辑:
重新加载您的表格视图:
[tableView reloadData];
【讨论】:
或者只是单元格!deleteRowsAtIndexPaths:withRowAnimation:
什么示例代码?你有你的项目,无论你面对我们回答的问题。我猜你遇到了模型数据数组的问题。而不是直接显示在 tablview 单元格中,首先将该通知添加到模型数组中,然后将其显示在您的 tableview 上。
如何向模型数组添加通知?以上是关于如何从xcode中的tableview中删除本地通知的主要内容,如果未能解决你的问题,请参考以下文章