Jeeter
Jeeter

Reputation: 6105

iOS - setting text of UITextView throws EXC_BAD_ACCESS

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.

Upvotes: 1

Views: 1283

Answers (2)

Sudha Tiwari
Sudha Tiwari

Reputation: 2461

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

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

Upvotes: 1

Yo_Its_Az
Yo_Its_Az

Reputation: 2073

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.

Upvotes: 0

Related Questions