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 09-09-2011, 07:41 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 5
Jackbenimble is on a distinguished road
Default UITableView - how to change color of an arbitrary row

Hi - I'm writing a multiple-choice quiz app, and I'm trying to figure out a way to change the color of an arbitrary row in a UITableView. When clicked, the app should stay on the same table view, but with the correct answer highlighted in green, and any incorrect response highlighted in red.

This means it needs to highlight two items if there's an incorrect answer - the incorrect, selected row and the correct, non-selected row. The second item is the more troubling one. The first I've been able to achieve by subclassing UITableVeiwCell and implementing the setSelected:animated method. But, I don't how to highlight (i.e. change the background color) of a non-selected row.

Any help or ideas would be much appreciated!
Jackbenimble is offline   Reply With Quote
Old 09-09-2011, 07:51 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Any specific reason why you are using a tableview for this?

Taking a look at the class reference for UITableView: Loading… you'll see a section of methods titled "Accessing Cells and Sections", there's a method there to do what you want.
baja_yu is offline   Reply With Quote
Old 09-09-2011, 09:17 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 5
Jackbenimble is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Any specific reason why you are using a tableview for this?

Taking a look at the class reference for UITableView: Loading… you'll see a section of methods titled "Accessing Cells and Sections", there's a method there to do what you want.
I got it. The cellForRowAtIndexPath. The thing that was throwing me was that I was not getting that you can make calls on the table from within the app - it's not just the framework that can do it.

As far as using the tableview, since it's a list of possible answers - albeit a fixed amount at this point - the list with it's touch paradigm seemed like a pretty standard and widely used widget. Which widget would you recommend? A Label or a button, or something?

Thanks for the hint
Jackbenimble is offline   Reply With Quote
Old 09-10-2011, 03:42 AM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

If the number of responses would change then the tableview might be an option, but in such games it usually doesn't, so a tableview seems to heavy for this. I'd probably go with a set of imageviews and labels. Besides eliminating the overhead you can also customize the look a lot easier, for example, instead of just changing background color you could provide custom images for different states and so on.
baja_yu is offline   Reply With Quote
Old 09-10-2011, 04:31 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 5
Jackbenimble is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
If the number of responses would change then the tableview might be an option, but in such games it usually doesn't, so a tableview seems to heavy for this. I'd probably go with a set of imageviews and labels. Besides eliminating the overhead you can also customize the look a lot easier, for example, instead of just changing background color you could provide custom images for different states and so on.
Yes, you're right, it's much simpler.

Question: Do you mean super-imposing the label over the imageView? Or do you actually set the text in the imageView, and the label is just a label?

Also, if I just want a color to populate the image - I will need to create or find an image of that color, correct?

Finally, after I show the answer, and the user clicks the "next question" button, how do I get the same view to reload?

Thanks for your great suggestions!

Last edited by Jackbenimble; 09-10-2011 at 04:36 PM.
Jackbenimble is offline   Reply With Quote
Old 09-12-2011, 06:50 AM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

The label would be superimposed on the image. That way you can have only a few images in the bundle (neutral, correct, wrong), and just change the text in the label over it.

As for the other question, you wouldn't actually reload the view, just change the contents (text's in labels, images etc).
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
background color, cell, uitableview

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: 413
10 members and 403 guests
apatsufas, Eclectic, fiftysixty, JackReidy, jeroenkeij, teebee74, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

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