hsousa / HCSStarRatingView

Simple star rating view for iOS written in Objective-C
MIT License
1.28k stars 196 forks source link

Star Rating keep same for Next time #56

Closed SanjeetVerma closed 7 years ago

SanjeetVerma commented 7 years ago

First of all i would to say Thanks for great library i am facing some issue like if i give the rating once so it become full of colour of star,now i want to keep remain if user appear next time into that screen. please help me out!

hsousa commented 7 years ago

Hi @SanjeetVerma!

That has to be done outside of this control. This is purely a visual component.

Persistence should be taken care of elsewhere.

From what you're describing, you should be passing an object to your view controller that stores the rating value... something like:

@interface MyViewController : UIViewController
@property (nonatomic) MyViewControllerViewModel *viewModel;
@end

@implementation MyViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.ratingView.value = self.viewModel.ratingValue;
}

@end

Then whenever you're creating your view controller:

MyViewController *vc = //whatever you're using to initialize the VC
MyViewControllerViewModel *viewModel = [MyViewControllerViewModel new];
viewModel.ratingValue = 5.f;

vc.viewModel = viewModel;

[self.navigationController pushViewController:vc];