uialertview - passing multiple data to database -


i have 2 buttons bring different alert views in same view pass different values on database, both work individually. problem if click on button 1 , after button 2, button 2 details don't sent over, , vis versa. don't know how fix this, ideas?

code im using:

-(void) addnewcomment:(nsstring*) newcomment withname:(nsstring *) routeid{  if (newcomment != nil){      nsmutablestring *poststring = [nsmutablestring stringwithstring:postcommenturl];      [poststring appendstring:[nsstring stringwithformat:@"?%@=%@", snewcomment, newcomment]];     [poststring appendstring:[nsstring stringwithformat:@"&%@=%@", srouteid, routeid]];     [poststring setstring:[poststring stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]];      nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl:[nsurl urlwithstring:poststring]];     [request sethttpmethod:@"post"];      postconnection = [[nsurlconnection alloc] initwithrequest:request delegate:self startimmediately:yes]; } }  -(void) updaterating:(nsstring*) newrating withname:(nsstring *) newrateno withname:(nsstring *) routeid{ //similar above }   - (ibaction)addcommentbutton:(id)sender{  uialertview * alert = [[uialertview alloc] initwithtitle:@"alert" message:@"add comment" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"add comment",nil]; alert.alertviewstyle = uialertviewstyleplaintextinput; alert.tag = 1; [alert show]; }  - (ibaction)ratebutton:(id)sender{  //similar above alert.tag = 2; [alert show]; }   - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex{ if(alertview.tag == 1) {     if (buttonindex == 0) {     nslog(@"cancel button clicked"); }     if (buttonindex == 1) {      self.addnewcommentstring = [[alertview textfieldatindex:0] text];      self.allcomments = [nsstring stringwithformat:@"%@\n\n%@",commenttextview.text, self.addnewcommentstring];     nslog(@"%@%@",routeidlabel ,allcomments);      [self addnewcomment:self.allcomments withname:routeidlabel.text];     [routeidlabel resignfirstresponder];     allcomments = nil;     routeidlabel.text = nil;     [[nsnotificationcenter defaultcenter] postnotificationname:@"test1" object:self];      } } else {     //similar above } } 

it looks sending parameters in querystring. try instead of post.

you try setting cache policy:

nsurl *url = [nsurl urlwithstring: poststring]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringlocalandremotecachedata timeoutinterval:15]; 

you try sending request , waiting response (not ideal, @ least see if makes difference):

nserror *error; nsurlresponse *response; nsdata *data = [nsurlconnection sendsynchronousrequest:request                                       returningresponse:&response                                                  error:&error]; 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -