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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-02-2010, 07:20 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 5
jossblowing is on a distinguished road
Question Different custom cells in a single UITableView? Sensible?

Hi all!
I'm writing a little app to display news. I have a UITableView with a single type of custom cell inside. But for the top news item I want to make it stand out.

I want this cell to scroll as normal with the rest of the content - but I only want the styling to apply to a single item of data.

I'm thinking I could achieve this by having 2 custom cells. So in -tableView:cellForRowAtIndexPath and -tableView:heightForRowAtIndexPath I would just have some kind of if statement to decide the size and which cell class to render.

I'm just wondering is this sensible? How might others go about this?

Thanks for any advice,
>>joss
jossblowing is offline   Reply With Quote
Old 05-02-2010, 10:22 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

What do you believe your alternatives are?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 05-03-2010, 12:42 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 92
funkyspider is on a distinguished road
Default

You can have as many custom table cells as you need. Every row could have its own cell if required.
funkyspider is offline   Reply With Quote
Old 05-03-2010, 01:46 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

Depending on how many rows you have in your table, having different cell heights may or may not work. If you have a lot of rows (several hundred) you could run into issues... because your heightForRowAtIndexPath method will be called for each one, and you don't have much time at startup to handle all these calls before the OS will decide to kill your app.

What would scale better would be to figure out a way to just have a single row height, and then just draw the cell differently for the first row (bolded font, or different colors, or something, while keeping the same row height).
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 05-03-2010, 02:34 AM   #5 (permalink)
Registered Member
 
mobileben's Avatar
 
Join Date: Jul 2009
Location: Zgrunturos
Posts: 161
mobileben is on a distinguished road
Default

Really depends on how good you are at managing your cells. We have custom cells, but don't go to the extent of changing the heights. We found it is easier to manage the more things you can "keep constant". We of course override the drawRect routine to custom draw everything in the cells. Everything but the background color that is.
__________________
Have a Poketastic time with QuitIt!
Arcade Basketball at it's best! Hoops Madness!
VS action on the iPad with Hoops Madness VS!
Sweet trailer here!
mobileben is offline   Reply With Quote
Old 05-03-2010, 05:17 PM   #6 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 5
jossblowing is on a distinguished road
Default

Thanks for all the responses guys - really interesting.

Yeah - I didn't know if there was a better way, I'm all very new to this so it's great to hear from all the experts. I guess the more rows the more expensive drawing custom cell heights can become. I imagine in my case there won't be more than 50 items so that should be manageable. I actually implemented it and it seems to work very nicely.

I've been looking at different news apps - and they take different approaches. FT.com, Tweetie (if you can call it news) - have variable size rows, whereas Byline, Telegraph, ITN and NYTimes have fixed heights. I honestly think a mobile user wants more information upfront with as little clicks as possible, so cutting-off sentences mid-flow doesn't quite work for me...

But great - thank you.
jossblowing is offline   Reply With Quote
Old 05-03-2010, 05:49 PM   #7 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

It's not so much the expense of drawing cells at different heights... it's just that if you have variable row heights, the OS will ask you the height for each row in your table up front (presumably so it knows how to properly draw the scroll indicator while the user is scrolling through the table).

But if you are only going to have 50 rows... or even a couple hundred... you should be fine. Although if you have to actually calculate different row heights for each row (like to figure out how much room you need to fully display snippets of text on a row-by-row basis), you might still run into performance issues that could cause your app to get killed.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, uitableview, uitableviewcell

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 333
21 members and 312 guests
Abidullah, baja_yu, cgokey, Domele, Duncan C, Fstuff, gbenna, givensur, guusleijsten, HowEver, iphonedevshani, jbro, mdpauley, n00b, newDev, Sami Gh, seokwon lee, SLIC, stanny, Steven.C, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:38 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0