从另一个类objective-C获取数组
我有一个xml文件,我把所有信息都放在xml文件中,并存储在数组中 以下是用于存储在阵列中的starDidElement文件:从另一个类objective-C获取数组,objective-c,ios,nsarray,Objective C,Ios,Nsarray,我有一个xml文件,我把所有信息都放在xml文件中,并存储在数组中 以下是用于存储在阵列中的starDidElement文件: -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDi
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"Presentation"]) {
NSLog(@"user element found – create a new instance of User class...");
app.presentationArray = [[NSMutableArray alloc] init];
thePresentation = [[Presentation alloc] init];
thePresentation.pLabel = [attributeDict objectForKey:@"label"];
NSLog(@"PLabel: %@", thePresentation.pLabel);
}else if ([elementName isEqualToString:@"slides"]) {
NSLog(@"Slides");
thePresentation.slides = [NSMutableArray array];
在我的头上我有
Presentation thePresentation;
你能帮我解释一下吗
提前谢谢
编辑:
Presentation *aPresentation = [app.presentationArray objectAtIndex:0];
NSLog(@"Presentation is: %@ and it's Slide Count is: %d",aPresentation.pLabel, aPresentation.slides.count);
Slide *aSlide = [aPresentation.slides objectAtIndex:0];
NSLog(@"Slide Label is: %@", aSlide.sLabel);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal];
btn.frame = rect;
[btn setTag:i];
[btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];
则日志为
[788:c07]演示文稿为:(空),幻灯片计数为:0
[788:c07]幻灯片标签为:(null)在viewController中添加一个公共方法,一旦xml解析完成,调用该公共方法就是说,您告诉viewController数据已准备就绪并更新UI 您可以使用appDelegate通知viewController数据已准备就绪,因为appDelegate将拥有您的viewController实例 编辑:您可以拥有以下内容:
//in viewController.h
- (void) viewFillUp;
//in viewController.m
-(void)viewFillUp
{
Slide *aSlide = [thePresentation.slides objectAtIndex:0];
NSLog(@"Slide Label is: %@", aSlide.sLabel);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal];
btn.frame = rect;
[btn setTag:i];
[btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];
}
//in appDelegate.h
- (void) parsingDone;
//in appDelegate.m
- (void) parsingDone
{
//suppose ur viewController instance is self.viewController
[self.viewController viewFillUp]
}
这样做会发生什么:
Presentation *aPresentation = [app.presentationArray objectAtIndex:0];
NSLog(@"Presentation is: %@ and it's Slide Count is: %d",aPresentation.pLabel, aPresentation.slides.count);
Slide *aSlide = [aPresentation.slides objectAtIndex:0];
NSLog(@"Slide Label is: %@", aSlide.sLabel);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal];
btn.frame = rect;
[btn setTag:i];
[btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];
但我都有发言权,请你写下你所说的代码,你的起始删除代码写在哪里。。?我的意思是,在哪个类或ViewController中,请您将其添加到您的答案中我需要代码我是objective C的新手,但您没有更改我的代码,这是一样的,我的问题是我不知道如何为我的对象添加值我应该修改什么来代替此幻灯片*aSlide=[presentation.slides objectAtIndex:0];或除此之外,您的做法与在Java中的做法基本相同。@HotLicks您能在回答部分中编写代码吗?请首先,我在未声明的标识符应用程序中出错,我在头文件中添加了AppDelegate应用程序;但是,由于未捕获的异常“NSInvalidArgumentException”,我在终止应用程序时出错,原因:'**-[NSPlaceholderString initWithString:]:nil参数“[788:c07]演示文稿为:(null),其幻灯片计数为:0[788:c07]幻灯片标签为:(null),这意味着您的
应用程序中没有任何内容。presentationArray
。没有向其添加演示文稿:(((我真的很想知道会有什么问题,请帮我到iPhone/iPad房间,让我们继续讨论。