tags:

views:

134

answers:

2

I want to display and implement the rating in the way apple does in the ipod app. Can anybody tell me how it is done. The code that i want to implement is to be written in a viewController.

Thanks in advance.

Providing the code would be useful. I am drawing the image in the implementation (.m)file of my UIViewController subclass inside touchesBegan: method. The errors at runtime are as follows:

<Error>: CGContextSaveGState: invalid context
<Error>: CGContextSetBlendMode: invalid context
<Error>: CGContextSetAlpha: invalid context
<Error>: CGContextTranslateCTM: invalid context
<Error>: CGContextScaleCTM: invalid context
<Error>: CGContextDrawImage: invalid context
<Error>: CGContextRestoreGState: invalid context
<Error>: CGContextClipToRect: invalid context
+2  A: 

The way I would approach it would be to respond to touches in the target view, and look at the touch location within the view.

I would split the view into sections, equal to the number of 'stars' at regular intervals, and when the touch is detected within one of these sections, set the value of the rating to the number of section.

Eg.

 _ _ _ _ _ 
|_|_|_|_|_|
     ^ touch here = 3

Then you could implement some drawing to correspond to the chosen rating to draw the amount of 'stars' that have been selected.

Jasarien
please see the edited part of the questions
I don't have any code to provide sorry, my answer was how I would approach it conceptually. The errors are telling you that you're attempting to draw to an invalid context. You should be drawing to the current context (using `UIGraphicsGetCurrentContext()`) or another context that you set up yourself and know is valid.
Jasarien
+2  A: 

5 buttons, with your own images for filled and unfilled stars. You'll need some custom logic to change the pictures on each click. I'd recommend setting a different tag on each button.

Rob Fonseca-Ensor
While this would work, and is a perfectly viable solution, it doesn't really emulate Apple's implementation from the iPod app, which the questioner was asking about. This method would produce a different user experience than implementing a single view that tracks touch locations.
Jasarien
please see the edited part of the question. Thanks to Rob Fonseca-Ensor and Jasarien for the replies. Please provide me a solution