I am unclear as to where I should create my objects. If I create them in viewDidLoad in my ViewController, obviously they can't be accessed outside that method. For example, when a UIButton is touched in a View, I want my objects to be modified. But if the objects were created in viewDidLoad (for example), the IBAction that fires开发者_如何学JAVA when a UIButton is touched doesn't know about my object.
I'm pretty obviously missing something very fundamental and would appreciate some pointers.
You can create them in viewDidLoad, but to make them accessable in your instance you'll have to make them ivars(instance variables) or properties.
You can read more about Properties in Objective-C 2.0 on cocoacast.com.
I recommend Apple's official book The Objective-C Programming Language:
- Class interface
- Referring to Instance Variables
- Declared Properties - Overview
- Using Properties
Declare that UIButton in the .h file... then you can able to access the button anywhere...
if you want to access the state any where in the code you just declare that as state(global declaration ) which should be in the .h file.The state can be alloc in the viewdidload or any method according to usage.
精彩评论