以编程方式设置NSTextField的文本 [英] Setting the text of an NSTextField programmatically

查看:320
本文介绍了以编程方式设置NSTextField的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个建立在IB(Xcode 4)上的GUI。

它有一个静态文本字段连接到NSTextField。从XML文件读取信息后,应该将文本更改为来自XML的任何内容

I have a GUI built on IB (Xcode 4).
It has a Static Text field connected to an NSTextField. After reading the information from an XML file it's supposed to change the text to whatever it is coming from the XML

.h如下:

IBOutlet NSTextField * DataBaseLocation;

.m

NSMutableArray* DBLoc = [[NSMutableArray alloc] initWithCapacity:1];
NSXMLElement* root  = [doc rootElement];
NSArray* DBarray = [root nodesForXPath:@"//DataBaseLocation" error:nil];
for(NSXMLElement* xmlElement in DBarray)
    [DBLoc addObject:[xmlElement stringValue]];

NSString * DBLocationString = [DBLoc objectAtIndex:0];
[DataBaseLocation setStringValue:DBLocationString];

NSLog(@"DBLoc: %@", DBLoc);

NSLog 显示 DBLoc 有正确的字符串,但文本字段为空,永远不会设置。

The NSLog shows that DBLoc has the correct string, yet the Text Field is empty and never gets set.

是的,我检查了IB中的连接。
任何想法?感谢!

yes, I checked the connections in IB. Any ideas? thanks!

推荐答案

找到答案。

NSXMLDocument with NSXMLDocumentTidyXML like:

I needed to initialize the NSXMLDocument with NSXMLDocumentTidyXML like:

NSXMLDocument* doc = [[NSXMLDocument alloc] initWithContentsOfURL: [NSURL fileURLWithPath:input] options:NSXMLDocumentTidyXML error:NULL];

这篇关于以编程方式设置NSTextField的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆