其他类复制字符串时出现问题

发布于 2024-10-30 17:31:30 字数 1251 浏览 1 评论 0原文

在我的应用程序中,我向网络服务器发送请求并获取一些结果,然后解析该结果并将该结果字符串存储到其他类对象字符串中。

例如:

@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];  
        }  

当我调试时,我可以看到 graphViewController.graphTempString 的值,但转到 GraphView 后,我看不到这些值。

我希望有人知道如何解决这个问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

哥,最终变帅啦 2024-11-06 17:31:30

传递价值的简单方法。

[[NSUserDefaults standardUserDefaults]setObject:resultString forKey:@"resultString"];
[[NSUserDefaults standardUserDefaults] synchronize];

在另一个类中使用这个值

NSString *resultString=[[NSUserDefaults standardUserDefaults]valueForKey:@"resultString"];

,或者你可以这样做。

graphViewController.graphTempString=self.tempString; 

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; 
云仙小弟 2024-11-06 17:31:30

你能试试

2nClassObj.tempString =[NSString stringWithFormat:@"%@",resultString];  

祝你好运吗

can you try

2nClassObj.tempString =[NSString stringWithFormat:@"%@",resultString];  

good luck

瑾夏年华 2024-11-06 17:31:30

@Pooja我建议你尝试通过在AppDelegate类中创建一个变量来将你的resultString提供给这个变量,然后从你的2ndClass中的这个变量中获取值 或在任何你想要的类中......你永远不会得到空值。

假设您的 AppDelegate 类的对象是 appDelegate,而 NSString 类型的变量是 stringValue。然后在您获取 resultString 的类中执行如下操作。

appDelegate.stringValue = resultString;

在您的 2ndClass 类中,像这样从此变量中获取值。

tempString =  appDelegate.stringValue;

你会得到数据......希望你明白我的意思。

祝你好运!

@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!

辞别 2024-11-06 17:31:30

如果添加一些 NSLog 语句会发生什么?

    if (grpahCall == YES) {
        graphViewController=[[GraphView alloc]init];

        NSLog(@"-%@-", tempString);
        graphViewController.graphTempString=tempString;  
        NSLog(@"-%@-", graphViewcontroller.graphTempString);

        [self.navigationController pushViewController:graphViewController animated:YES];  
    }

我希望看到同样的东西输出两次?你能告诉我你在控制台中得到了什么吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文