手势识别器星级评定系统

发布于 2024-12-19 19:22:16 字数 3340 浏览 1 评论 0原文

我在 https://github.com/dlinsin/DLStarRating 使用了这个星级评级系统,手势工作正常然而,它似乎没有正确使用委托,因此当我选择一颗星星时,评级不会刷新。这是我的代码:

.main 文件

- (void)viewDidLoad
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    //check if value has been previously saved
    if( ![defaults stringForKey:@"username"] ) {        

        CustomerLogin *customerlogin = [[CustomerLogin alloc]
                                                  initWithNibName:@"CustomerLogin" bundle:nil];
        [self presentModalViewController:customerlogin animated:YES];
//        customerlogin.view.frame = CGRectMake(0, 0, 700, 900);
//      customerlogin.view.center = CGPointMake( 768/2, 1024/2);
        //[self.navigationController pushViewController:customerlogin animated:YES];

        [customerlogin release];


    }

    UIBarButtonItem * sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStyleBordered target:self action:@selector(Submit)];

    self.navigationItem.rightBarButtonItem = sortButton;
    [sortButton release];

    rating.delegate = self;
    comments.delegate = self;
    bestnight.delegate = self;

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_texture.png"]];

    self.view.backgroundColor = background;

    [background release];

    self.title = @"Write Review";

    [super viewDidLoad];

    //Star touch
    DLStarRatingControl *customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(0,0, 320, 100) andStars:5];
    customNumberOfStars.backgroundColor = [UIColor clearColor];
    customNumberOfStars.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    customNumberOfStars.rating = 3;
    [self.view addSubview:customNumberOfStars];
    [customNumberOfStars release];

}

-(void)newRating:(DLStarRatingControl *)control :(NSUInteger)rating 
{
    self.rating.text = [NSString stringWithFormat:@"%d star rating",rating];
}

.header 文件

#import "DLStarRatingControl.h"

@class Customer;
@class Place;

@interface CreateReview : UIViewController <UITextFieldDelegate,UITextViewDelegate,DLStarRatingDelegate>
{
    Customer*customer;
    Place*place;
    IBOutlet UITextField * bestnight;
    IBOutlet UITextView * comments;
    IBOutlet UITextField * rating;
    IBOutlet UILabel * testValueLabel;

    NSString * identifier;
    NSString * password;
    NSString * username;


}

@property (nonatomic, retain) IBOutlet UITextField * bestnight;
@property (nonatomic, retain) IBOutlet UITextView * comments;
@property (nonatomic, retain) IBOutlet UITextField * rating;
@property (nonatomic, retain) Customer*customer;
@property (nonatomic, retain) Place*place;
@property (nonatomic, retain) IBOutlet UILabel * testValueLabel;
@property (nonatomic, retain) NSString * identifier;
@property (nonatomic, retain) NSString * password;
@property (nonatomic, retain) NSString * username;

-(id)initWithPlace:(Place*)p;
-(void)newRating:(DLStarRatingControl *)control :(NSUInteger)rating;


@end

I used this star rating system at https://github.com/dlinsin/DLStarRating the gesture is working fine however it dosen't seem to be using the delegate correctly and therefore when I select a star the rating is not refreshing. Here is my code:

.main File

- (void)viewDidLoad
{

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    //check if value has been previously saved
    if( ![defaults stringForKey:@"username"] ) {        

        CustomerLogin *customerlogin = [[CustomerLogin alloc]
                                                  initWithNibName:@"CustomerLogin" bundle:nil];
        [self presentModalViewController:customerlogin animated:YES];
//        customerlogin.view.frame = CGRectMake(0, 0, 700, 900);
//      customerlogin.view.center = CGPointMake( 768/2, 1024/2);
        //[self.navigationController pushViewController:customerlogin animated:YES];

        [customerlogin release];


    }

    UIBarButtonItem * sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStyleBordered target:self action:@selector(Submit)];

    self.navigationItem.rightBarButtonItem = sortButton;
    [sortButton release];

    rating.delegate = self;
    comments.delegate = self;
    bestnight.delegate = self;

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background_texture.png"]];

    self.view.backgroundColor = background;

    [background release];

    self.title = @"Write Review";

    [super viewDidLoad];

    //Star touch
    DLStarRatingControl *customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(0,0, 320, 100) andStars:5];
    customNumberOfStars.backgroundColor = [UIColor clearColor];
    customNumberOfStars.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    customNumberOfStars.rating = 3;
    [self.view addSubview:customNumberOfStars];
    [customNumberOfStars release];

}

-(void)newRating:(DLStarRatingControl *)control :(NSUInteger)rating 
{
    self.rating.text = [NSString stringWithFormat:@"%d star rating",rating];
}

.header file

#import "DLStarRatingControl.h"

@class Customer;
@class Place;

@interface CreateReview : UIViewController <UITextFieldDelegate,UITextViewDelegate,DLStarRatingDelegate>
{
    Customer*customer;
    Place*place;
    IBOutlet UITextField * bestnight;
    IBOutlet UITextView * comments;
    IBOutlet UITextField * rating;
    IBOutlet UILabel * testValueLabel;

    NSString * identifier;
    NSString * password;
    NSString * username;


}

@property (nonatomic, retain) IBOutlet UITextField * bestnight;
@property (nonatomic, retain) IBOutlet UITextView * comments;
@property (nonatomic, retain) IBOutlet UITextField * rating;
@property (nonatomic, retain) Customer*customer;
@property (nonatomic, retain) Place*place;
@property (nonatomic, retain) IBOutlet UILabel * testValueLabel;
@property (nonatomic, retain) NSString * identifier;
@property (nonatomic, retain) NSString * password;
@property (nonatomic, retain) NSString * username;

-(id)initWithPlace:(Place*)p;
-(void)newRating:(DLStarRatingControl *)control :(NSUInteger)rating;


@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衬遮猫 2024-12-26 19:22:16

您似乎没有为 DLStarRatingControl 设置委托:

尝试在设置评级控件时添加 customNumberOfStars.delegate = self;

It appears you aren't setting the delegate for the DLStarRatingControl:

try adding customNumberOfStars.delegate = self; when setting up your rating control

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文