I am working on a very simple app just for learning.This convert celcius value into fahrenheit value.It has a single view with two UITextFields and a button.After entering a celcius value in 1st uitextfield and clicking on the button a function with argument as "-(void)requestCelciusandresponseFrnht:(NSString *)textfieldstring" is called.This method is in my NSOBject class named "WebServiceCall". webservice is sent, xml is parsed and the result is populated in a nsstring variable named "soapResults".Below is the structure of my code:
i am having a NSObject class with variable as "soapresults":
@interface WebServiceCall : NSObject <UITextFieldDelegate,NSXMLParserDelegate> {
NSString *msgLength;
//web service access
NSMutableData *webData;//contains modifiable data in form of bytes
NSMutableString *soapResults;//To hold the value of fahrenheit from parsed xml resulting thrugh webservice
BOOL elementFound;
ends
NSURLConnection *conn;
NSXMLParser *xmlParser;
}
@property (nonatomic,retain) NSMutableString *soapResults;
-(void)requestCelciusandresponseFrnht:(NSString *)textfieldstring;
the implementation code starts as:
#import "WebServiceCall.h"
@implementation WebServiceCall @synthesize soapResults,test;
-(void)requestCelciusandresponseFrnht:(NSString *)textfieldstring{
//here the code goes for soap message,NSMUtableRequest,http heade,body & NSURLconnection }
EDIT:
-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
NSLog(@"the value of soap result is as : %@",soapResults);//**i am able to get fahrenheit value here**
WebServicesAppDelegate *appDelegate=(WebServicesAppDelegate *)[[UIApplication sharedApplication]delegate];
appDelegate.results=[[NSString alloc]init];
appDelegate.results=soapResults;
NSLog(@"appDelegate.results value of NSObject class is :%@",appDelegate.results);
//**i am able to set fahrenheit value here in appDelegate.results**
}
Edit:Now according to your suggestion changes in my app delegate class as: The header file .h:-
@class WebServicesViewController;
@interface WebServicesAppDelegate : NSObject { NSMutableString *results;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet WebServicesViewController *viewController; @property (nonatomic, retain) NSMutableString *results;
@end the implementation file .m as:
#import "WebServicesAppDelegate.h"
#import "WebServicesViewController.h"
@implementation WebServicesAppDelegate
@synthesize window=_window; @synthesize results;
now i am trying to access the soapResults variable in my view controller some thing like this:
-(IBAction) buttonClicked:(id) sender
{ NSLog(@"button clicked and celcius value sent as argument");
clsvarWebServiceCall=[[WebServiceCall alloc]init];
[clsvarWebServiceCall requestandresponsewithfrnhtReq:txtcels.text];
WebServicesAppDelegate *appDelegate=(WebServicesAppDelegate *)[[UIApplication sharedApplication]delegate];
NSLog(@"appDelegate.results of viewController is %@",appDelegate.results);
here i am getting soapResults Value as null
EDIT:my whole nslog/trace :`2011-09-07 15:03:22.948 WebServices[1717:207] view controller loaded
2011-09-07 15:03:41.266 WebServices[1717:207] button clicked and celcius value sent as argument
2011-09-07 15:03:41.291 WebServices[1717:207] appDelegate.results of viewController is (null)
2011-09-07 15:03:41.299 WebServices[1717:207] soapResults of viewController is (null)
2011-09-07 15:03:42.091 WebServices[1717:207] didreceiveresponse method called in nsobject class 2011-09-07 15:03:42.098 WebServices[1717:207] didReceiveData method called in nsobject class
2011-09-07 15:03:42.103 WebServices[1717:207] connectionDidFinishLoading method called in nsobject class
2011-09-07 15:03:42.112 WebServices[1717:207] didStartElement method called in nsobject class
2011-09-07 15:03:42.117 WebServices[1717:207] didStartElement method called in nsobject class
2011-09-07 15:03:42.122 WebServices[1717:207] didStartElement method called in nsobject class
2011-09-07 15:03:42.127 WebServices[1717:207] didStartElement method called in nsobject class
2011-09-07 15:03:42.133 WebServices[1717:207] foundCharacters method called in nsobject class
2011-09-07 15:03:42.139 WebServices[1717:207] didEndElement method called in nsobject class
2011-09-07 15:03:42.146 WebServices[1717:207] the value of soapResult in NSObject class is as : 122
2011-09-07 15:03:42.159 WebServices[1717:207] appDelegate.results value of NSObject class is :122
2011-09-07 15:03:42.175 WebServices[1717:207] didEndElement method called in nsobject class
2011-09-07 15:03:42.179 WebServices[1717:207] the value of soapResult in NSObject class is as : 122
2011-09-07 15:03:42.184 WebServices[1717:207] appDelegate.results value of NSObject class is :122
2011-09-07 15:03:42.190 WebServices[1717:207] didEndElement method called in nsobject class
2011-09-07 15:03:42.196 WebServices[1717:207] the value of soapResult in NSObject class is as : 122
2011-09-07 15:03:42.200 WebServices[1717:207] appDelegate.results value of NSObject class is :122
2011-09-07 15:03:42.204 WebServices[1717:207] didEndElement method called in nsobject class
2011-09-07 15:03:42.208 WebServices[1717:207] the value of soapResult in NSObject class is as : 122
2011-09-07 15:03:42.329 WebServices[1717:207] appDelegate.results value of NSObject class is :122` if you look at the nslog the soapREsults orappDelegate.soapResults of view controller is called first and i thik thats why it is null and the result from the soap result is coming later and it is unable to update the soap result value in view controller? any suggestion?