[英]How to access NSArray in another View
I have some problems with my XML parser, written in obj-c. 我的以obj-c编写的XML解析器存在一些问题。 The parser itself is fine but I cant access the result Array in the DetailView. 解析器本身很好,但是我无法在DetailView中访问结果数组。
I need the values of the array created by the Parser Class in my Master and DetailViewController. 我需要在Master和DetailViewController中由解析器类创建的数组的值。
In MasterViewController I do this: 在MasterViewController中,我这样做:
MasterViewController.h MasterViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "TouchXML.h"
#import "Parser.h"
@class Parser;
@interface MasterViewController : UITableViewController{
Parser *theParser;
}
MasterViewController.m MasterViewController.m
- (void)viewDidLoad
{
theParser = [[Parser alloc] init];
[theParser startParser:xmlPath]; //Now the parser runs and parses all needed values into arrays
}
Then I push on click the DetailView and I want to access the values there too. 然后,我单击“ DetailView”,然后我也要访问其中的值。
UniViewController.h UniViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Parser.h"
@interface UniViewController : UITableViewController{
Parser *theParser;
}
UniViewController.m UniViewController.m
- (void)viewDidLoad
{
NSLog(@"Name: %@",[[theParser.listArray objectAtIndex: 0]valueForKey:@"name"]);
}
Here I want to access the the Array from the parser but I always get the value (null) ? 在这里,我想从解析器访问Array,但是我总是得到值(null)? In the debugger I saw that theParser has 0x0000 which cant be right... After I do theParser = [[Parser alloc] init]; 在调试器中,我看到theParser具有0x0000不能正确...在执行完之后,theParser = [[Parser alloc] init]; here, it has an hex value but I still get the (null). 在这里,它有一个十六进制值,但我仍然得到(null)。
How can I access the Array values from the DetailView? 如何从DetailView访问Array值?
Would be really nice if someone could explain me the problem here. 如果有人可以在这里向我解释问题,那将是非常好的。
Thanks. 谢谢。
Your detail view has to have a pointer to the array that your MasterView creates (via the parser), try this: 您的详细信息视图必须具有一个指向MasterView创建的数组的指针(通过解析器),请尝试以下操作:
(void)viewDidLoad
{
aParser = [[Parser alloc] init];
[aParser startParser:xmlPath];
myUniView.theParser = aParser; //myUniView is just the detail view you're pushing
and then after this you can push your detail view. 然后,您可以按一下详细信息视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.