[英]How to access NSArray in another View
我的以obj-c编写的XML解析器存在一些问题。 解析器本身很好,但是我无法在DetailView中访问结果数组。
我需要在Master和DetailViewController中由解析器类创建的数组的值。
在MasterViewController中,我这样做:
MasterViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "TouchXML.h"
#import "Parser.h"
@class Parser;
@interface MasterViewController : UITableViewController{
Parser *theParser;
}
MasterViewController.m
- (void)viewDidLoad
{
theParser = [[Parser alloc] init];
[theParser startParser:xmlPath]; //Now the parser runs and parses all needed values into arrays
}
然后,我单击“ DetailView”,然后我也要访问其中的值。
UniViewController.h
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Parser.h"
@interface UniViewController : UITableViewController{
Parser *theParser;
}
UniViewController.m
- (void)viewDidLoad
{
NSLog(@"Name: %@",[[theParser.listArray objectAtIndex: 0]valueForKey:@"name"]);
}
在这里,我想从解析器访问Array,但是我总是得到值(null)? 在调试器中,我看到theParser具有0x0000不能正确...在执行完之后,theParser = [[Parser alloc] init]; 在这里,它有一个十六进制值,但我仍然得到(null)。
如何从DetailView访问Array值?
如果有人可以在这里向我解释问题,那将是非常好的。
谢谢。
您的详细信息视图必须具有一个指向MasterView创建的数组的指针(通过解析器),请尝试以下操作:
(void)viewDidLoad
{
aParser = [[Parser alloc] init];
[aParser startParser:xmlPath];
myUniView.theParser = aParser; //myUniView is just the detail view you're pushing
然后,您可以按一下详细信息视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.