I’m still quite new to Xcode etc, so Im a bit fuzzy when it comes do creating/using objects in Xcode.
For example, I used a tutorial for creating a GestureRecognizer in code – it’s pretty simple.
Right now I have only this in my .h:
@interface PlayPage : UIViewController <UIGestureRecognizerDelegate>
And this in my .m:
UITapGestureRecognizer *tapTwo=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap)];
[tapTwo setDelegate:self];
[tapTwo setNumberOfTapsRequired:2];
[tapTwo setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:tapTwo]; //adds it to view
Here are my question(s):
1) If I also want to see the GestureRecognizer in IB along with the above code (perhaps so I can change some settings since I’m not familiar with everything) how do I accomplish that?
2) How would you decide when to use all code vs. a mix of code/IB ? Is it strictly a matter of style/comfort/familiarity?
3) It seems declaring different objects requires different ‘setup’ code (UITextLabel vs GestureRecognizer vs UITextField,for example) – how do you know when to use which code?
Thanks for helping to clear this up.
In Xcode 4.x Interface builder there are
UIGestureRecognizerobjects that you can drag onto your views. So you would need to add theUIGestureRecognizerin Interface builder (if you need to do any more config in code then connect them up with an outlet as well).I try and do anything I can in IB and drop to code when I have to but it is a matter of preference.
Start typing and look at the autocompletion options to jog your memory. But more importantly every time you use a class you have not used before you should at least skim the documentation to see what is suggested. Half of the questions on this site could easily be solved if the question poster actually bothered to look at the vast documentation available.
Update
You need to create the
UIGestureRecognizerin Interface Builder not your code.In Interface Builder ensure that the
Utilitiespain is visible and drag and drop aUIGestureRecognizerof the required class onto your viewThis is what the
UIGestureRecognizerclass look like:You then configure the object in the
Utilitiespanel. If you want to be able to access this object in your code then you will need anIBOutlet.In your classes header file add a new ivar for this
In the implementation file synthesize this
Then back in Interface builder connect this up by
ctrl+click+draggingfrom theFile's Ownerto theUIGestureRecognizersubclass. Then selecting your ivar from the window that appears: