When I add new view, I always do same and boring work.
If I add UIWebView, I would do follows,
- add codes to header file. ( declare, property )
- add codes to source file. ( synthesize, viewDidUnload, dealloc )
- add UIWebView in IB and connect to the outlet in File’s Owner.
[ViewController.h]
@interface ViewController : UIViewController
{
UIWebView *_webView;
}
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@end
[ViewController.m]
@synthesize webView = _webView;
- (void)viewDidUnload
{
[super viewDidUnload];
self.webView = nil;
}
- (void)dealloc
{
[_webView release];
[super dealloc];
}
What if I should add 3 labels and 2 buttons?
What if I have to add textview and some imageviews?
Don’t you think it is boring? I would like to listen to your idea.
I hope there will be more easy and simple way to add outlet to the code.
Does anybody have a good idea? 🙂
When using
Interface Builder, If you select an Object drag it’s reference to your header, you’ll see a popup where you can name it so theres less typing for you to do. As seen below:This will automatically declare the
IBOutlet UIButton *myButtonfor you, and insert thereleaseandnilcode intodeallocandviewDidUnloadmethods.Same method also works for actions, as seen below.
Once you
Connectit will automatically insert the new Action-(IBAction)cancelSelected:(id)senderinto your@implementationclass.Point being, all that’s boring for you to do can be done in
2Reference connections, and inputting data into2fields. 🙂Hope this helps!