UITextView problem

Joined
Jun 3, 2011
Messages
54
Reaction score
0
Points
6
Dear All!

I am trying to read text file from local system as well as using url (using NSURLConnection). And I am able to view the content of file on console.

I want them to be displayed on TextView using UITextView or by any other mean.

I created a button on clicking of which viewer with file content should be seen.

Code:
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
							     initWithTitle:@"View" 
							    style:UIBarButtonItemStylePlain 
							    target:self 
							    action:@selector(textviewtest)]
                                                            autorelease];

Further I am trying to use the UITextView as:

Code:
- (void) textviewtest {
    textview = [[UITextView alloc] init];	 
    NSString *data = @"this is textview";	
    [self.textview  setText: data];
    [self.textview setFont:[UIFont fontWithName:@"Helvetica" size:16.0]];
    [data release];		
	
}

in above "data" is just for testing purpose and later I will display the NSMutabledata object on this textview.

Kindly help me out where the mistake I am doing.
Or provide me some reference / tutorial where I can learn how to use UITextView.

Thanks and regards
Sagar Priyadarshi
 
Joined
Feb 25, 2009
Messages
2,112
Reaction score
71
Points
48
Your Mac's Specs
Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
Ok a couple of things -

1) You have a memory leak in the block of code you've shown. Basically each time you press that button you're allocating a textview, but you're not releasing the previous one.

2) I don't know what kind of an IVar textview is, I'm assuming it's not linked to a UITextView that is in a xib file - as such, when you allocate one, you usually need to set its frame to set its size to ultimately be in the view.

3) You never add the textview to the actual view that is displayed on the screen so you will never see it.
 
OP
S
Joined
Jun 3, 2011
Messages
54
Reaction score
0
Points
6
Thanks for the reply..
Still feeling difficulty..I understand this theoretical aspects.
Can you please let me know location of related resources and some tutorial?

Thanks
 
Joined
Feb 25, 2009
Messages
2,112
Reaction score
71
Points
48
Your Mac's Specs
Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
Off hand I don't know of any - I learned how to do it a long time ago from a book I think. I can create a small tutorial for you, but I don't think I'll have time to do it until Wednesday if that's ok.
 
OP
S
Joined
Jun 3, 2011
Messages
54
Reaction score
0
Points
6
Hey Thanks

I just solved the problem :)
I was not releasing the textview as well as it was not being added to any subview
 
Joined
Feb 25, 2009
Messages
2,112
Reaction score
71
Points
48
Your Mac's Specs
Late 2013 rMBP, i7, 750m gpu, OSX versions 10.9.3, 10.10
You know if you want to get creative, you could animate the textview on to (and off of when you toggle it off) the screen - would make for a more interesting presentation then just appearing :)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top