gpt4 book ai didi

ios - 在NSNotificationCenter中的通知的userInfo中传递空的NSIndexPath

转载 作者:行者123 更新时间:2023-12-01 19:43:58 26 4
gpt4 key购买 nike

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

但是,我收到一个错误:

*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'* -[__ NSPlaceholderDictionary
initWithObjects:forKeys:count:]:尝试从中插入nil对象
对象[1]

如何通过NSNotificationCenter传递空索引?

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
}
];

最佳答案

您可以传递带有负值的NSIndexPath,并在接收方检查该值是否为负。

代码:

NSIndexPath *selectedIndex = [NSIndexPath indexPathForRow:-1 inSection:-1];

关于ios - 在NSNotificationCenter中的通知的userInfo中传递空的NSIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50871681/

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