gpt4 book ai didi

iphone - TBXML 解析问题,而值无法在 UILabel 中获取

转载 作者:行者123 更新时间:2023-11-28 22:53:22 24 4
gpt4 key购买 nike

在我的应用程序中,我正在使用 TBXML 解析器,我需要从 xml 文件中获取一个值并将其打印在标签上...这是我在服务器中的 xml 文件

 <gold>
<price>
<title>22 K Gold</title>
</price>
<price>
<title>24 K Gold</title>
</price>
</gold>

任何我的 Viewcontroller.h 看起来像

#import <UIKit/UIKit.h>
#import "TBXML.h"

@interface ViewController : UIViewController{

IBOutlet UILabel *lab;
TBXML *tbxml;
}



@end

我的 Viewcontrooler.m 看起来像

 - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSData *xmlData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://www.abcde.com/sample.xml"]];
tbxml = [[TBXML alloc]initWithXMLData:xmlData];


TBXMLElement * root = tbxml.rootXMLElement;

if (root)
{
TBXMLElement * elem_PLANT = [TBXML childElementNamed:@"price" parentElement:root];
while (elem_PLANT !=nil)
{
TBXMLElement * elem_BOTANICAL = [TBXML childElementNamed:@"title" parentElement:elem_PLANT];
NSString *botanicalName = [TBXML textForElement:elem_BOTANICAL];
lab.text=[NSString stringWithFormat:@"re %@", botanicalName];

elem_PLANT = [TBXML nextSiblingNamed:@"price" searchFromElement:elem_PLANT];

elem_BOTANICAL = [TBXML childElementNamed:@"title" parentElement:elem_PLANT];

botanicalName = [TBXML textForElement:elem_BOTANICAL];
lab1.text=[NSString stringWithFormat:@"re %@", botanicalName];
}
}

}

我收到 BAD_ACCESS 线程。我是否遗漏了任何东西...请帮助...

最佳答案

lab.text=[NSString stringWithFormat:@"re %@",elem_BOTANICAL];

编辑 1.0:

lab.text=[NSString stringWithFormat:@"re %@", botanicalName];

编辑 2.0:

lab.text=[NSString stringWithFormat:@"re %@", botanicalName];

NSString *plantName = [TBXML textForElement: elem_PLANT];

lab1.text=[NSString stringWithFormat:@"re %@", plantName];

关于iphone - TBXML 解析问题,而值无法在 UILabel 中获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11339793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com