其他类复制字符串时出现问题
在我的应用程序中,我向网络服务器发送请求并获取一些结果,然后解析该结果并将该结果字符串存储到其他类对象字符串中。
例如:
@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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
传递价值的简单方法。
在另一个类中使用这个值
,或者你可以这样做。
Easy way to pass value.
and in another class use this value like this
or u may do it like this.
你能试试
祝你好运吗
can you try
good luck
@Pooja我建议你尝试通过在
AppDelegate
类中创建一个变量来将你的resultString
提供给这个变量,然后从你的2ndClass中的这个变量中获取值
或在任何你想要的类中......你永远不会得到空值。假设您的
AppDelegate
类的对象是appDelegate
,而NSString
类型的变量是stringValue
。然后在您获取resultString
的类中执行如下操作。在您的 2ndClass 类中,像这样从此变量中获取值。
你会得到数据......希望你明白我的意思。
祝你好运!
@Pooja i suggest you to try doing this by making a variable in
AppDelegate
class give yourresultString
to this variable and then fetch the value from this variable in your2ndClass
or in any class you want .....you will never get null value.Lets suppose the object of your
AppDelegate
class isappDelegate
and the variable which ofNSString
type is letsstringValue
. Then in your class where you are getting theresultString
do like this.And in your
2ndClass
class take the value from this variable like this.You will get the data.....Hope you got my point.
Good Luck!
如果添加一些 NSLog 语句会发生什么?
我希望看到同样的东西输出两次?你能告诉我你在控制台中得到了什么吗?
What happens if you add some NSLog statements?
I would expect to see the same thing output twice? Can you tell me what you get in the console?