将 txt 从数组解析为 UILabel [英] parsing txt from array to UILabel

查看:49
本文介绍了将 txt 从数组解析为 UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的开始失去活下去的意志了,这段代码快把我逼疯了!

I'm actually starting to loose the will to live, this piece of code is driving me nuts!

我正在尝试将 mathspractice.txt 的内容放入 *myLabel

I'm trying to get the content of mathspractice.txt into *myLabel

我使用的数组是:

-(void)loadText
{
    NSArray *wordListArray = [[NSArray alloc] initWithArray:
    [[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"mathspractice" ofType:@"txt"]
    encoding:NSMacOSRomanStringEncoding error:NULL] componentsSeparatedByString:@"\n"]];
    self.theMathsPractice = wordListArray;
    [wordListArray release];
}

然后我试图将它传递给 *myLabel

and then I'm trying to pass it into *myLabel

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,100,960,40)];
        myLabel.text = *theMathsPractice;
        [myScrollView addSubview:myLabel];
        [myLabel release];
        }

有人可以帮忙吗?

推荐答案

快速检查您的 theMathsPractice 是一个 NSArray,而不是一个 NSString,这是您想要分配的标签的文本属性.在将数组分配给标签之前,您至少应该将该数组重新格式化为某种字符串.

It looks on quick inspection that your theMathsPractice is an NSArray, not an NSString, which is what you'd want to assign to the label's text property. You should at least format that array back into a string of some sort before assigning it to the label.

(也不确定你为什么在赋值中用 * 取消引用它——我认为这会引发编译器错误,因为裸非引用的 Objective-C 对象并不是真的允许.)

(Also not sure why you're dereferencing it with the * in the assignment-- I would think that would throw a compiler error, since naked non-reference Objective-C objects are not really allowed.)

这篇关于将 txt 从数组解析为 UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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