【问题标题】:Call Method with parameters in AppDelegate在 AppDelegate 中使用参数调用方法
【发布时间】:2014-09-18 10:46:22
【问题描述】:

好的,所以我的 CoreLocation 东西在我的 AppDelegate 中启动并运行,并且有一些使用它的方法。 现在,我想从我的 ViewController 调用 AppDelegate 中的这些方法之一。但是,此方法所需的参数 [即location stuff],我的 ViewController 不知道。 我现在应该在我的 ViewController 中设置整个 CoreLocation hoopla,还是有更简单、更智能、更优雅的方法? (我很害怕这个问题表明我有点怀念编程的基础知识,但我愿意自欺欺人) 谢谢打扰...

示例:在我的 AppDelegate 中,有一个方法叫做

-(void) sendDataToServer:(CLLocation *)newLocation

它需要一个位置作为输入。 CoreLocation 在 AppDelegate 中初始化,因此位置参数在 APpDelegate 中是已知的。但不在 ViewController 中。

【问题讨论】:

    标签: ios methods parameters appdelegate


    【解决方案1】:

    您可以通过以下方式访问 AppDelegate:[UIApplication sharedApplication].delegate

    【讨论】:

    • 好的,但是如何将参数传递给 AppDelegate 中的方法,只有 AppDelegate 知道?
    • 与任何其他课程一样
    • 我已经编辑了我的问题,希望能够让我的问题更加清晰。
    • 在 AppDelegate 中调用您有权访问 newLocation 的其他方法,并在该方法中调用 sendDataToServer:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 2014-06-29
    • 2018-04-12
    相关资源
    最近更新 更多