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 12-30-2008, 02:13 PM   #1 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default Sample code for creating custom UITableViewCells?

Can somebody point me to good sample code for creating custom UITableViewCells?

I've customized the cells created by the button views in the UICatalog application, but those are pretty simple-minded.

I need to pack a fair amount of information into a cell, and need fine control of placement and of the font sizes, etc.

I am writing an instant messaging application, and want to be able to display the message sender's nickname, the date and time of the message, and the message text. I'd like the user's name and the date/time to be on the left and right of a small bar at the top of the cell, and the message text to take up the majority of the rest of the cell. I will probably add an optional "avatar" icon on the left of the cell as an option at some point.

I also want the cell to get taller to fit longer messages. Yesterday somebody pointed me to a method, sizeWithFont:constrainedToSize:, that should let me calculate the height I need to display a given string at a specified font and size, and at a certain width, allowing for word wrapping. I think I can work that out.

At some point I may want to change the text in a message to use a web view, so I can display hyperlinks, and allow the user to click on them. I don't know how I'll size the view (and the cell) if I need to do that. Is there an equivalent call to sizeWithFont:constrainedToSize: for web views?

I'm thinking that I can brute-force lay out my different subviews in the cell, but I'm hoping there's an easier way.

Thanks in advance for any help you can provide.


Regards,

Duncan C
Duncan C is offline   Reply With Quote
Old 01-01-2009, 11:56 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 10
bigcheese is on a distinguished road
Default

Hi,

i love this tutorial:

iPhone Programming Tutorial - Creating a ToDo List Using SQLite Part 2 | iCodeBlog

have fun,
bigcheese
bigcheese is offline   Reply With Quote
Old 01-01-2009, 09:57 PM   #3 (permalink)
New Member
 
Join Date: Dec 2008
Posts: 10
physcab is on a distinguished road
Default UITableView Color??

Hello all,

I'm trying to get my tableView to be all black except for the text color. I believe this is the UI of the Shazaam App.

I've tried all the solutions on this forum and others, and it still doesn't work:

tableView.backgroundColor = [UIColor blackColor];

However, it works in the SQLite books example, so I think the problem is with my setup. In interface builder, my files go:

View Controller > MyView > TableView and the code above is in MyView.m file.

Any thoughts? I would like the background color of the table to be black, the cell background to be black, and the cell text to be white.

I would appreciate ANY help!
physcab is offline   Reply With Quote
Old 01-01-2009, 10:21 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by physcab View Post
Hello all,

I'm trying to get my tableView to be all black except for the text color. I believe this is the UI of the Shazaam App.

I've tried all the solutions on this forum and others, and it still doesn't work:

tableView.backgroundColor = [UIColor blackColor];

However, it works in the SQLite books example, so I think the problem is with my setup. In interface builder, my files go:

View Controller > MyView > TableView and the code above is in MyView.m file.

Any thoughts? I would like the background color of the table to be black, the cell background to be black, and the cell text to be white.

I would appreciate ANY help!
I'm guessing that you need to set the background color on your cells to black as well as setting the background color on the tableview's background to black. The cells normally cover the tableview.
Duncan C is offline   Reply With Quote
Old 01-02-2009, 01:56 AM   #5 (permalink)
New Member
 
Join Date: Dec 2008
Posts: 10
physcab is on a distinguished road
Default ok got it to work

ok, i finally figured it out.

I ended up pretty much copying word for word from the SQLite Books example.

I originally had: UIViewController > MyView > TableView.

I changed it to: MyViewController > TableView.

I think there was a problem with having an extra View which the table sat on top of, or it could have been the fact that I had a general UIViewController which was in charge of all my TabBar Views. So I made sure each TabBar View had its own _ViewController.

This is still pretty finicky, so if someone else understands it better, feel free to clarify....or reference this to another more appropriate thread.
physcab is offline   Reply With Quote
Old 01-02-2009, 12:15 PM   #6 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: Hawaii
Posts: 52
lab12 is on a distinguished road
Default Sample Code

Hi Duncan,

THe best sample code for creating custom cells that I could find is from Erica Sadun's book (and for anyone to download here) cookbooksamples - Google Code

Chapter 6 09a "preferences table" - I could put alot of text in the custom cell but I couldn't figure out how to make it scroll (or not sure if that is even possible) - if you figure that out let me know
lab12 is offline   Reply With Quote
Old 01-03-2009, 12:21 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: London, UK
Posts: 250
mattjgalloway is on a distinguished road
Default

I have a basic UITableViewCell tutorial at:
One Eye Open » Custom UITableViewCell

I'm hoping to improve on my tutorials at the start of this year. Sorry if it doesn't help though.
__________________
Beard Booth HD - See what you'd look like with a beard today!

My iPhone Apps
My iPhone Tutorials
mattjgalloway is offline   Reply With Quote
Reply

Bookmarks

Tags
layout, sample code, 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: 336
7 members and 329 guests
chemistry, iOS.Lover, lendo, leostc, Leslie80, pbart, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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