null 传递给在 Xcode 7 中需要非 null 参数的被调用者

Posted

技术标签:

【中文标题】null 传递给在 Xcode 7 中需要非 null 参数的被调用者【英文标题】:null passed to a callee that requires a non-null argument in Xcode 7 【发布时间】:2015-09-22 08:30:49 【问题描述】:

在 Xcode 7 中,我收到了这个黄色警告: null 传递给需要非 null 参数的被调用者。我的代码如下,第五行突出显示(零部分) (mainVC.currentActiveNVC.viewControllers = nil;) 请帮我。谢谢。

if (!mainVC.isInitialStart)

    CGRect openedFrame = mainVC.currentActiveNVC.view.frame;
    [mainVC.currentActiveNVC.view removeFromSuperview];
    mainVC.currentActiveNVC.viewControllers = nil;
    mainVC.currentActiveNVC = nil;

    mainVC.currentActiveNVC = destinationNVC;
    mainVC.currentActiveNVC.view.frame = openedFrame;
    navItem = destinationNVC.navigationBar.topItem;


【问题讨论】:

听别人说是因为在ios9中,需要将其设为空字符串,我尝试将nil替换为“”,但它不起作用,太糟糕了 【参考方案1】:

你可以传递一个空数组。

mainVC.currentActiveNVC.viewControllers = @[];

【讨论】:

【参考方案2】:

呜呜呜!!我找到了答案。只需将“nil”更改为“@[]”@[] 表达式用于 iOS9 中的空字符串。

【讨论】:

@[] 是一个空数组,而不是一个空字符串。而且跟iOS9没有关系,是ObjC语言的特性。

以上是关于null 传递给在 Xcode 7 中需要非 null 参数的被调用者的主要内容,如果未能解决你的问题,请参考以下文章

将变量传递给在 TabBar 中调用的视图

将 int 文字传递给在 java 中采用整数的方法

颤振:(24658):PlatformException(network_error,com.google.android.gms.common.api.ApiException:7:,null,nu

传递给在 SwiftUI 中不带参数的调用的参数

如何使用事件将 json 输入传递给在无服务器中部署的 Cron 计划 Lambda?

Clojure - 将组件传递给在启动或停止期间未执行的功能