在为 iPhone 编程时如何保持 NSArray 对所有方法可用
我正在制作一个使用一些 NSArray 的 iPhone 应用程序。现在我必须在每个方法中生成数组。我知道必须有一种更有效的方法来做到这一点,比如在初始化期间创建 NSArray,然后可供所有方法使用。问题是,当我在 ViewDidLoad 方法中创建 NSArrays 时,当我尝试在其他方法中调用它们时,我收到一条错误,指出它们无法识别。也许我试图错误地初始化 NSArray 或者在错误的位置?任何有关这方面的信息将不胜感激。感谢您抽出时间。
I am making an iPhone app that uses a few NSArrays. Right now I have to generate the arrays in each method. I know there has to be an more efficient way of doing this, like having the NSArrays created during initialization and then being available to all methods after that. The problem is, that when I create the NSArrays in the ViewDidLoad method, when I try to call them in other methods, I get an error stating that they are not recognized. Perhaps I am trying to initialize the NSArrays incorrectly or maybe in the wrong spot? Any info on this would be appreciated. Thank you for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将数组声明为属性。合成它并在 ViewDidLoad 方法中初始化。
即标头的
实现:
You should declare your array as a property. Synthesize it and initialize in your ViewDidLoad Method.
i.e. the header
the implementation: