gpt4 book ai didi

iphone - 在 UILabel 中显示变量

转载 作者:行者123 更新时间:2023-11-28 23:08:27 25 4
gpt4 key购买 nike

我正在从服务器上的 XML 文件中获取一些数据,这是文件的解析:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {

if ( [elementName isEqualToString:@"ipayregs"] ) {

msgAdded = [[attributeDict objectForKey:@"added"] retain];
msgId = [[attributeDict objectForKey:@"id"] intValue];

msgNome = [[NSMutableString alloc] init];
msgName = [[NSMutableString alloc] init];
msgMatricula = [[NSMutableString alloc] init];
msgSenderCode = [[NSMutableString alloc] init];

inNome = NO;
inName = NO;
inMatricula = NO;
inSenderCode = NO;


}

if ( [elementName isEqualToString:@"nome"] ) { inNome = YES; }
if ( [elementName isEqualToString:@"nome"] ) { inName = YES; }
if ( [elementName isEqualToString:@"matricula"] ) { inMatricula = YES; }
if ( [elementName isEqualToString:@"sendercode"] ) { inSenderCode = YES; }


}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

if ( inNome ) { [msgNome appendString:string]; }
if ( inName ) { [msgName appendString:string]; }
if ( inMatricula ) { [msgMatricula appendString:string]; }
if ( inSenderCode ) { [msgSenderCode appendString:string]; }

}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

if ( [elementName isEqualToString:@"ipayregs"] ) {

[messages addObject:[NSDictionary dictionaryWithObjectsAndKeys:msgAdded,@"added",msgNome,@"nome",msgMatricula,@"matricula",msgSenderCode,@"sendercode",msgName,@"name",nil]];

[[messages reverseObjectEnumerator] allObjects];

lastId = msgId;

[msgAdded release];
[msgNome release];
[msgName release];
[msgMatricula release];
[msgSenderCode release];

}

if ( [elementName isEqualToString:@"nome"] ) { inNome = NO;}
if ( [elementName isEqualToString:@"name"] ) { inName = NO;}
if ( [elementName isEqualToString:@"matricula"] ) { inMatricula = NO;}
if ( [elementName isEqualToString:@"sendercode"] ) { inSenderCode = NO;}
}

如您所见,下载的数据存储在 vars(@"nome",@"matricula"..) 中。但是我如何在 UILabels 中显示这些值,例如 | label.text = @"nome"|?

最佳答案

看起来数据实际上存储在 msgNome 中。 @"nome"是字符串表达式,不是实例变量。所以,你会设置 label.text = msgNome;

另外,你应该:

inNome = [elementName isEqualToString:@"nome"]; 

而不是所有额外的 if 语句。

关于iphone - 在 UILabel 中显示变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8814210/

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