iphone - Multiple rating bars with DYRateView -


i have view 3 ratings bars on it.

how tell them apart in code? right if change top 1 sees fine if change either or other 2 cannot separate them 1 another.

the code git https://github.com/dyang/dyrateview

- (void)changedtonewrate:(nsnumber *)rate {     nsstring *rating = [nsstring stringwithformat:@"rate: %d", rate.intvalue];     nslog(@"rating: %@",rating); } 

this sees changing.

and .m file

#import "survey.h"  @implementation survey  @synthesize btnsubmit;  - (void)setupeditablerateview {     dyrateview *rateservice = [[dyrateview alloc] initwithframe:cgrectmake(0, 55, self.view.bounds.size.width, 40) fullstar:[uiimage imagenamed:@"starfulllarge@2x.png"] emptystar:[uiimage imagenamed:@"staremptylarge@2x.png"]];     rateservice.padding = 20;     rateservice.alignment = rateviewalignmentcenter;     rateservice.editable = yes;     rateservice.delegate =self;     [scroller addsubview:rateservice];     [rateservice release];      dyrateview *ratefood = [[dyrateview alloc] initwithframe:cgrectmake(0, 130, self.view.bounds.size.width, 40) fullstar:[uiimage imagenamed:@"starfulllarge@2x.png"] emptystar:[uiimage imagenamed:@"staremptylarge@2x.png"]];     ratefood.padding = 20;     ratefood.alignment = rateviewalignmentcenter;     ratefood.editable = yes;     ratefood.delegate = self;    [scroller addsubview:ratefood];    [ratefood release];    dyrateview *ratecleanliness = [[dyrateview alloc] initwithframe:cgrectmake(0, 200, self.view.bounds.size.width, 40) fullstar:[uiimage imagenamed:@"starfulllarge@2x.png"] emptystar:[uiimage imagenamed:@"staremptylarge@2x.png"]];    ratecleanliness.padding = 20;    ratecleanliness.alignment = rateviewalignmentcenter;    ratecleanliness.editable = yes;    ratecleanliness.delegate = self;    [scroller addsubview:ratecleanliness];    [ratecleanliness release]; }  - (bool)textfieldshouldreturn:(uitextfield *)textfield {     [textfield resignfirstresponder];    return yes; }  - (void)changedtonewrate:(nsnumber *)rate {     nsstring *rating = [nsstring stringwithformat:@"rate: %d", rate.intvalue];     nslog(@"rating: %@",rating); }  - (ibaction)btnsubmit:(id)sender{  }  -(ibaction)mainmenu{  [self dismissmodalviewcontrolleranimated:yes];    }  - (void)didreceivememorywarning {     // releases view if doesn't have superview.     [super didreceivememorywarning];      // release cached data, images, etc aren't in use. }  #pragma mark - view lifecycle  - (void)viewdidload {     [super viewdidload];     [scroller setscrollenabled:yes];     [scroller setcontentsize:cgsizemake(320, 600)];     scroller.backgroundcolor = [uicolor clearcolor];      [self setupeditablerateview];      [btnsubmit usegreenconfirmstyle];  }    - (void)viewdidunload  {     [super viewdidunload];      // release retained subviews of main view.     // e.g. self.myoutlet = nil;  }   - (bool)shouldautorotatetointerfaceorientation:(uiinterfaceorientation)interfaceorientation  {      // return yes supported orientations      return (interfaceorientation == uiinterfaceorientationportrait);  }   @end 

update

ok new code added if statement

- (void)rateview:(dyrateview *)rateview changedtonewrate:(nsnumber *)rate {     nsstring *barname = [nsstring stringwithformat:@"%@", rateview];     if (barname == @"rateview1") {         nsstring *bar1 = [nsstring stringwithformat:@"rate: %d", rate.intvalue];         nslog(@"bar 1: %@",bar1);     }else if(barname == @"rateview2"){         nsstring *bar2 = [nsstring stringwithformat:@"rate: %d", rate.intvalue];         nslog(@"bar 2: %@",bar2);     }else{        nslog(@"no bar: %@",barname);     }    self.ratelabel.text = [nsstring stringwithformat:@"rate: %d", rate.intvalue];    } 

it works instead of getting "rateview1" or 2 or 3.

 no bar: <dyrateview: 0x78229b0; frame = (0 40; 320 20); opaque = no; layer =  <calayer:0x7824900>> 

which correct in nature hoping name of rateview such "rateview1"

solution:

in .h file @property 2 or 3 bars

@property(nonatomic, retain) dyrateview *rateview1,*rateview2; 

in .m @synthesize them

@synthesize rateview1; @synthesize rateview2; 

then

(void)setupeditablerateview {     rateview1 = [[dyrateview alloc] initwithframe:cgrectmake(0, 40, self.view.bounds.size.width, 20) fullstar:[uiimage imagenamed:@"starfulllarge.png"] emptystar:[uiimage imagenamed:@"staremptylarge.png"]];     rateview1.padding = 20;     rateview1.alignment = rateviewalignmentcenter;     rateview1.editable = yes;     rateview1.delegate = self;     [self.view addsubview:rateview1];     [rateview1 release];      rateview2 = [[dyrateview alloc] initwithframe:cgrectmake(0, 100, self.view.bounds.size.width, 20) fullstar:[uiimage imagenamed:@"starfulllarge.png"] emptystar:[uiimage imagenamed:@"staremptylarge.png"]];     rateview2.padding = 20;     rateview2.alignment = rateviewalignmentcenter;     rateview2.editable = yes;     rateview2.delegate = self;     [self.view addsubview:rateview2];     [rateview2 release];      // set label view display rate     self.ratelabel = [[[uilabel alloc] initwithframe:cgrectmake(0, 80, self.view.bounds.size.width, 20)] autorelease];     self.ratelabel.textalignment = uitextalignmentcenter;     self.ratelabel.text = @"tap above rate";     [self.view addsubview:self.ratelabel]; } 

then

- (void)rateview:(dyrateview *)rateview changedtonewrate:(nsnumber *)rate {      if (rateview == rateview1) {         nsstring *bar1 = [nsstring stringwithformat:@"rate: %d", rate.intvalue];         nslog(@"bar 1: %@",bar1);     }else if(rateview == rateview2){         nsstring *bar2 = [nsstring stringwithformat:@"rate: %d", rate.intvalue];         nslog(@"bar 2: %@",bar2);     }else{         nslog(@"no bar: %@",rateview);     }          self.ratelabel.text = [nsstring stringwithformat:@"rate: %d", rate.intvalue];    } 

thanks using dyrateview!

the current version of dyrateview doesn't support listening multiple instances @ same time, doesn't mean can't that. :)

if don't mind updating source code, can find method named notifydelegate in dyrateview.m, , change [self.delegate performselector:@selector(changedtonewrate:) withobject:[nsnumber numberwithfloat:self.rate]] [self.delegate performselector:@selector(rateview:changedtonewrate:) withobject:self withobject:[nsnumber numberwithfloat:self.rate]]. in way able pass rateview parameter listener.

i haven't tried above code yet don't have access mac @ point, think should give idea regarding how achieve goal.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -