Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-22-2009, 05:45 PM   #11 (permalink)
rwetmore
Registered Member
 
Join Date: Feb 2009
Posts: 9
Default

Quote:
Originally Posted by kooljava2 View Post
Thanks for the solution. It works beautifully. Couple of questions:

1. Why do we need a customview. Why can't we use just UILabel only?
2. Is there a memory leak here for customview and the label?

Thanks
  1. You could use a UILabel; it's a UIView subclass after all. As a matter of fact, Apple's docs suggest returning a UILabel as an example. If you read salboy's code, though, you'll see that the label bounds X coordinate is set to 10.0 so that it won't bump against the left side of the table. And it's set inside a view because...

    I'm not sure specifically how UITableView handles section titles, but since they bump up against each other as they slide out of view I imagine they're simply views being moved directly over the contents of the tableView as it's tracking. In the default case, there's already a view with an embedded label offset inside the view. When you return the section header text via tableView:titleForHeaderInSection:, it's simply setting the default label's text property.

    If you'd just passed a UILabel, it would be offset to the bounds of the section header frame, and draw the text at the extreme left of the table. Try it.

    Just as a point of style, I probably would have init'ed customView a bit differently:
    Code:
    UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, tableView.bounds.size.width, 44.0)] autorelease];
    The view's X coordinate doesn't make much of a difference. It's the label's offset you're worried about.

    Oh, and to mimic the standard UITableView behavior, I'd set the header view's backgroundColor to a color with a 0.9 or so alpha component. If you wanted to use gray, it'd look like:
    Code:
    customView.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.9];
  2. Yes, both the view and label are leaking. Personally, I'd alloc the view as autorelease (because you have to return it) and release the label after you've added it to the view. The view will be released when its superview is released. (Well, actually when its autoreleasePool is drained...)
rwetmore is offline   Reply With Quote
 

» Advertisements
» Online Users: 283
15 members and 268 guests
ADY, antonwilliams, dacapo, dcool, HemiMG, jakerocheleau, leahov, masc2279, michelle, MozyMac, nobre84, sly24, smithdale87, thh022, vogueestylee
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,877
Threads: 89,222
Posts: 380,720
Top Poster: BrianSlick (7,129)
Welcome to our newest member, peterkessler45
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:17 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.