iOS - setting text of UITextView throws EXC_BAD_ACCESS

…衆ロ難τιáo~ 提交于 2019-12-11 11:52:33

问题


I have a UITextView which I have created programmatically in the following code:

NSLog(@"creating the first blurb");
blurb = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
[blurb setText:total];
blurb.backgroundColor = [UIColor redColor];

where blurb is defined as a UITextView in the @interface.

Here's where I'm having the problem:

total is an NSString that is defined to get the text from a .txt file from a specified domain. It is mutated as:

 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];

However, when I run the code, I get an instance of EXC_BAD_ACCESS thrown at the setText: line of the top code block.

I have tried printing total out using an NSLog statement, and that seems to work just fine. Can anyone see what I'm doing wrong? Thanks.


回答1:


try this... May be it lose reference......

total = [[NSString stringWithContentsOfURL:urlRequest encoding:NSUTF8StringEncoding error:nil]copy];



回答2:


Why not trying to create an NSString and assign the text to that. And then you can try to print the NSString and see if that works. Just a suggestion.



来源:https://stackoverflow.com/questions/14018419/ios-setting-text-of-uitextview-throws-exc-bad-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!