我有一个 UITextView
,它是我在以下代码中以编程方式创建的:
NSLog(@"creating the first blurb");
blurb = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[blurb setText:total];
blurb.backgroundColor = [UIColor redColor];
其中 blurb
被定义为 @interface
中的 UITextView
。
这是我遇到问题的地方:
total
是一个 NSString
,它被定义为从指定域的 .txt
文件中获取文本。
它被突变为:
NSString *url = @"https://sites.google.com/site/paloaltoapps/tbnappsource-password-blackr3d/Updates.txt";
NSURL *urlRequest = [NSURL URLWithString:url];
total = [NSString stringWithContentsOfURL:urlRequest encoding:NSUTF8StringEncoding error:nil];
但是,当我运行代码时,我得到了一个 EXC_BAD_ACCESS
的实例,该实例抛出到顶部代码块的 setText:
行。
我已经尝试使用 NSLog
语句打印出 total
,这似乎工作得很好。
谁能看到我做错了什么?谢谢。
最佳答案
试试这个...可能会失去引用......
total = [[NSString stringWithContentsOfURL:urlRequest encoding:NSUTF8StringEncoding error:nil]copy];
关于iOS - UITextView 的设置文本抛出 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14018419/