[英]Gesture recogniser star rating system
我在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
您似乎沒有為DLStarRatingControl設置委托:
嘗試添加customNumberOfStars.delegate = self;
在設置您的評級控制時
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.