我有两个按钮,它们在同一个视图中显示不同的警报视图,它们将不同的值传递给数据库,两者都单独工作。问题是,如果我单击按钮 1 并在按钮 2 之后单击按钮 2 的详细信息,则不会发送过来,反之亦然。我不知道如何解决这个问题,有什么想法吗?
我使用的代码:
-(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 to the 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 to the 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 to the above
}
}