首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在userInfo中传递NSNotificationCenter通知的空NSNotificationCenter

在userInfo中传递NSNotificationCenter通知的空NSNotificationCenter
EN

Stack Overflow用户
提问于 2018-06-15 08:21:37
回答 1查看 63关注 0票数 1

我有一个特定的场景,当一个订单列表(NSMutableArray)是空的,因此所选的索引(NSIndexPath)也应该是空的(我正在使用nil)。我正在使用NSNotificationCenter传递这些数据,以在应用程序的其他地方触发表中的更新。

但是,我收到了一个错误:

*终止应用程序由于未登录的异常'NSInvalidArgumentException',原因:'* -__NSPlaceholderDictionary initWithObjects:forKeys:count::尝试从objects1插入零对象‘

如何通过NSNotificationCenter传递空索引

代码语言:javascript
复制
NSMutableArray *filteredAndSortedOrders = [[NSMutableArray alloc] init];
NSIndexPath *selectedIndex = nil;//[NSIndexPath indexPathForRow:0 inSection:0]]//The problem with this is that it's non-empty
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_RELOAD_TABLE_AND_DATA
                                                    object:self
                                                  userInfo:@{
                                                             @"filteredAndSortedOrders":[filteredandSortedOrders copy],
                                                             @"selectedIndex":selectedIndex
                                                             }
 ];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-15 08:30:14

您可以使用负值传递NSIndexPath,并在接收端检查该值是否为负值。

代码:

代码语言:javascript
复制
NSIndexPath *selectedIndex = [NSIndexPath indexPathForRow:-1 inSection:-1];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50871681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档