Je suis nouveau à IOS je veux afficher la réponse de la poste dans la vue d'alerte. Dans nslog j'ai montré la réponse. J'ai besoin quand j'ai cliqué sur l'affichage d'alerte de bouton peut afficher ma réponse.Response in alert view
codage:
-(void) sendDataToServer : (NSString *) method params:(NSString *)str{
NSData *postData = [str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[str length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL]];
NSLog(@"%@",str);
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:request delegate:self];
if(theConnection){
mutableData = [[NSMutableData alloc]init];
}
}
alerview:
- (IBAction)butt1:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Value"
message:@"%@"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"ok", nil];
[self sendDataToServer :@"POST" params:str];
[alert show];
}
délégués après la méthode: ici i obtenir une réponse à json111 que je montrais à NSLog mais avec succès en vue d'alerte i FAILED
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[mutableData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
return;
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError* error111;
json111 = [NSJSONSerialization JSONObjectWithData: mutableData
options:kNilOptions
error:&error111];
NSLog(@"%@",json111);
}
[![emptyvalue in alertview][1]][1]
UIAlertView est déconseillés dans iOS9, à cet endroit l'utilisation UIAlertviewController –
i besoin valeur de réponse de méthode post pas de valeur textfield @ Anbu.Karthik –
@ A.sonu oh glace, attendez que je modifie mon Anser –