Wrox Programmer Forums
|
BOOK: Beginning iOS 4 Application Development
This is the forum to discuss the Wrox book Beginning iOS 4 Application Development by Wei-Meng Lee; ISBN: 978-0-470-91802-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 4 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2011, 07:50 PM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 4 page 97 UIButton Question

Can someone please explain to me why, at the top of page 97, the code is like this:

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

INSTEAD OF:

button = [[UIButton alloc] buttonWithType:UIButtonTypeRoundedRect];

How does the button object get allocated? Does the 'buttonWithType' method do the allocating itself?
 
Old January 9th, 2011, 03:53 PM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

+ (id)buttonWithType:(UIButtonType)buttonType is a class method that handles the allocation and initialization of a UIButton for you (note the + sign in front of the return value). It returns an autoreleased object. Many classes have convenience methods for creating members of the class: e.g. [NSDictionary dictionary], [NSString stringWithFormat:…] etc
In many cases this simplifies (less typing, easier memory management) the creation of a new object. With UIButton it is the only way, outside of Interface Builder, to create a button.
Bob





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 15 Page 524 Question crazy BOOK: Professional JavaScript for Web Developers 2nd edition ISBN: 9780470227800 1 September 14th, 2010 02:49 PM
Question about page redirection - chapter 15 janilane BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 August 30th, 2010 07:59 PM
Chapter 16 Page 576 Question jsymons BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 September 25th, 2009 03:20 AM
Update and Inner Join Question - Access 97 snoopy92211 Access VBA 1 February 28th, 2005 04:30 PM
Chapter 2 page 48 'register_globals' question wndy26 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 5 July 1st, 2004 11:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.