2016-05-09 3 views
0

empty value in alertview Ich bin neu bei IOS Ich möchte Antwort von Beitrag in Alarmansicht anzeigen.in NSLog ich zeigte Antwort. ich brauche, als ich Knopfwarnungsansicht anklickte, kann meine Antwort anzeigen.Antwort in Alarmansicht

Codierung:

-(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]; 

} 

post-Methode Delegierten: hier i Antwort in json111 bekommen, dass ich erfolgreich in NSLog zeigte aber in Alarmansicht gescheitert i

-(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] 

Antwort

1

ändern Sie dies in

aktualisiert Antwort

@interface myViewController : UIViewController <UIAlertViewDelegate> 


-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 


NSError* error111; 
json111 = [NSJSONSerialization JSONObjectWithData: mutableData 
             options:kNilOptions 
             error:&error111]; 
NSLog(@"%@",json111); 

NSArray *temp = [ json111 objectForKey:@"Currencies"]; 

// you can directly fetch like 
NSDictionary *fetchDict = [temp objectAtIndex:0]; 
    NSDictionary *fetchUnit = [temp objectAtIndex:1]; 
// finally you can fetch like 
    NSString * total = [fetchDict objectForKey:@"total"]; 
    NSString * one_unit = [fetchUnit objectForKey:@"one_unit"]; 

    //updated 
    NSString *final = [NSString stringWithFormat:@"%@ , %@", total,one_unit]; 

// in here you can assign the value to Alert 


UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Value" 
               message:final 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"ok", nil]; 

alert.tag = 100; 
[alert show]; 


} 




- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (alertView.tag == 100) 
{ 
if (buttonIndex == 0) 
{ 
    // ok button pressed 
    //[self sendDataToServer :@"POST" params:str]; 
}else 
{ 
    // cancel button pressed 
} 
} 
+1

UIAlertView in iOS9 veraltet ist, an diesem Ort Einsatz UIAlertviewController –

+0

ich brauche Antwortwert von post-Methode nicht Textfeld Wert @ Anbu.Karthik –

+0

@ A.sonu oh Eis, nur warte ich meine Anser –

0

Sie sollten die Grundlagen der NSString wissen, siehe here.

0

Sie können Ihre Antwort in einem NSString speichern und diese Zeichenfolge dann im Nachrichtenfeld Ihrer Warnmeldungsansicht übergeben.

jedoch, wie von IOS 8,

UIAlertView veraltet. Verwenden Sie UIAlertController mit einem preferredStyle von UIAlertControllerStyleAlert statt

0

ändern Benachrichtigung anzeigen, wie folgend:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Value" 
               message:[NSString stringWithFormat:@"Response Message : %@",str] 
               delegate:self 
             cancelButtonTitle:@"Cancel" 
             otherButtonTitles:@"ok", nil]; 

Dies wird Ihre Antwortnachricht anstelle% @ anzuzeigen ..

Wenn Sie Daten senden möchten Server ein Klicken Sie auf alertView, Sie müssen Code in alertView schreiben Delegierter clickedButtonAtIndex

Hoffe es er lps ..

Verwandte Themen