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 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.
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?
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.
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.
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).