问题
In my app I am sending a request to the web server and getting some results, then I am parsing this result and storing this result string into other class object string.
For example:
@interface GraphView : UIViewController<UITabBarControllerDelegate> {
NSMutableString *graphTempString;
}
@property(nonatomic,retain) NSMutableString *graphTempString;
@end
TSUClass .m
implementing NSURLConnection(),
connectionDidFinishLoading(),
-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName
namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict()
-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"statusTEResult"])
{
tempString=soapResults;
if (grpahCall == YES) {
graphViewController=[[GraphView alloc]init];
graphViewController.graphTempString=tempString;
[self.navigationController pushViewController:graphViewController animated:YES];
}
When I am debugging I can see the value of graphViewController.graphTempString
but after going to GraphView, I am not able to see the values.
I hope some one know how to solve this issue.
回答1:
Easy way to pass value.
[[NSUserDefaults standardUserDefaults]setObject:resultString forKey:@"resultString"];
[[NSUserDefaults standardUserDefaults] synchronize];
and in another class use this value like this
NSString *resultString=[[NSUserDefaults standardUserDefaults]valueForKey:@"resultString"];
or u may do it like this.
graphViewController.graphTempString=self.tempString;
回答2:
can you try
2nClassObj.tempString =[NSString stringWithFormat:@"%@",resultString];
good luck
回答3:
@Pooja i suggest you to try doing this by making a variable in AppDelegate
class give your resultString
to this variable and then fetch the value from this variable in your 2ndClass
or in any class you want .....you will never get null value.
Lets suppose the object of your AppDelegate
class is appDelegate
and the variable which of NSString
type is lets stringValue
. Then in your class where you are getting the resultString
do like this.
appDelegate.stringValue = resultString;
And in your 2ndClass
class take the value from this variable like this.
tempString = appDelegate.stringValue;
You will get the data.....Hope you got my point.
Good Luck!
回答4:
What happens if you add some NSLog statements?
if (grpahCall == YES) {
graphViewController=[[GraphView alloc]init];
NSLog(@"-%@-", tempString);
graphViewController.graphTempString=tempString;
NSLog(@"-%@-", graphViewcontroller.graphTempString);
[self.navigationController pushViewController:graphViewController animated:YES];
}
I would expect to see the same thing output twice? Can you tell me what you get in the console?
来源:https://stackoverflow.com/questions/5565438/problem-in-copy-string-for-other-class