我有一个UILabel
并且UIButton
在不同的页面中,我想从xml
文件中读取它们的标题,但是我得到了NULL
价值,在我的XML parser
课堂上当我使用时NSLOG
我有我的答案但是当我想设置它们时我有NULL
,请你帮我实现这个?
提前致谢!
我的 XML 解析器:
- (Presentation1NameXML *) initXMLParser {
appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"Presentation1Name"]) {
appDelegate.books = [[NSMutableArray alloc] init];
NSLog(@"The Prices Count");
}
else if ([elementName isEqualToString:@"Presentation"]) {
presentation = [[Presentation alloc] init];
presentation.pLabel = [attributeDict objectForKey:@"label"];
NSLog(@"khengggg %@",presentation.pLabel);
// }else if ([elementName isEqualToString:@"Slides"]){
// slides = [[Slide alloc] init];
}
if([elementName isEqualToString:@"slide"]) {
slid = [[Slide alloc] init];
NSLog(@"Processing Element: %@", elementName);
slid.index = [[attributeDict objectForKey:@"index"] integerValue];
NSLog(@"Reading index value :%i", slid.index);
slid.sLabel = [attributeDict objectForKey:@"label"];
NSLog(@"Reading label value :%@", slid.sLabel);
slid.identifier = [attributeDict objectForKey:@"identifier"];
NSLog(@"Reading identifier value :%@", slid.identifier);
}
NSLog(@"Processing Element: %@", elementName);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(@"Processing Value: %@", currentElementValue);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"Presentation1Name"]){
return;
}
if([elementName isEqualToString:@"Presentation"]) {
[appDelegate.books addObject:presentation];
presentation = nil;
}
// if ([elementName isEqualToString:@"Slides"]){
// [appDelegate.books addObject:slides];
// slides = nil;
// return;
// }
if ([elementName isEqualToString:@"slide"]){
[appDelegate.books addObject:slid];
slid = nil;
}else
[presentation setValue:currentElementValue forKey:@"pLabel"];
//[presentation setValue:currentElementValue forKey:elementName];
currentElementValue = nil;
}
我的标签代码:我得到(空)
appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];
label.textColor = [UIColor greenColor];
Presentation *p1 = [appDelegate.books objectAtIndex:0];
NSLog(@"aaaaaaaaa aaaa %@", p1);
label.text = p1.pLabel;
我的按钮代码:我得到(空)
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
Slide *s1 = [appDelegate.books objectAtIndex:0];
NSLog(@" test %@", s1.sLabel);
我的对象类演示链接
我的对象类幻灯片链接