Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Status
Not open for further replies.

altivec 2003

macrumors regular
Original poster
Feb 8, 2003
135
0
Texas
Well, I have just started programming in cocoa after doing a lot of procedural c in mac os 9. I think that the ideas behind the object approach are neat, but they are taking a lot more time to learn than I had hoped. I have a question specifically about the text view object. I am practicing coding in this language by making a simple text-based rpg with the text display in a text view. Becuase I couldn't figure out how to add text I made up this method which other than the problem that I will get to works quite well:

- (void)addtexttodisplay:(NSString *)textToAdd
{
originaltext = [displayText string];
totaltext = [NSString stringWithFormat: @"%@%@",originaltext,textToAdd];
[displayText setString:totaltext];
}


I simplay call this function to add text to the object displayText which is a NSTextView. My main problem is that when the program outputs enough text, there becomes the necessity to scroll, and I can't figure out how to get the program to automatically go to the last line in the text. It requires that the user scroll down manually. If you have any idea how to help solve my problem please help me :) Thanks.
 

Fukui

macrumors 68000
Jul 19, 2002
1,630
18
Re: Cocoa question....

Originally posted by altivec 2003
Well, I have just started programming in cocoa after doing a lot of procedural c in mac os 9. I think that the ideas behind the object approach are neat, but they are taking a lot more time to learn than I had hoped. I have a question specifically about the text view object. I am practicing coding in this language by making a simple text-based rpg with the text display in a text view. Becuase I couldn't figure out how to add text I made up this method which other than the problem that I will get to works quite well:

- (void)addtexttodisplay:(NSString *)textToAdd
{
originaltext = [displayText string];
totaltext = [NSString stringWithFormat: @"%@%@",originaltext,textToAdd];
[displayText setString:totaltext];
}


I simplay call this function to add text to the object displayText which is a NSTextView. My main problem is that when the program outputs enough text, there becomes the necessity to scroll, and I can't figure out how to get the program to automatically go to the last line in the text. It requires that the user scroll down manually. If you have any idea how to help solve my problem please help me :) Thanks.
Tyr to talk to the scrollview that surrounds the NSTextField and tell it to scroll downwards after or during the time the text is being added to the textfield, once you've got the container you can get its bounds and compare it to the size of the NSTextField inside...then you can get when you need to scroll it. Once you have your scroll method done, you could also use an NSTimer to to smothly scroll the view downwards or something...

I think you should use NSScrollView's scrollLineDown method to scroll the line down, one line at a time...that might be easier. But you have to subclass...

P.S Try and download AppKido by Andy Lee, its really easy to search apples docs with.
 

altivec 2003

macrumors regular
Original poster
Feb 8, 2003
135
0
Texas
Re: Re: Cocoa question....

Originally posted by Fukui
Tyr to talk to the scrollview that surrounds the NSTextField and tell it to scroll downwards after or during the time the text is being added to the textfield, once you've got the container you can get its bounds and compare it to the size of the NSTextField inside...then you can get when you need to scroll it. Once you have your scroll method done, you could also use an NSTimer to to smothly scroll the view downwards or something...

I think you should use NSScrollView's scrollLineDown method to scroll the line down, one line at a time...that might be easier. But you have to subclass...

P.S Try and download AppKido by Andy Lee, its really easy to search apples docs with.

Thanks, I'll experiment with this. If scrollLineDown only goes one line I might have a little trouble there are multiple lines that go out-of-bounds, so to speak, at once. Is there a way to test how much text is beneath and do a for loop?
 

altivec 2003

macrumors regular
Original poster
Feb 8, 2003
135
0
Texas
Re: Re: Cocoa question....

Originally posted by Fukui
Tyr to talk to the scrollview that surrounds the NSTextField and tell it to scroll downwards after or during the time the text is being added to the textfield, once you've got the container you can get its bounds and compare it to the size of the NSTextField inside...then you can get when you need to scroll it. Once you have your scroll method done, you could also use an NSTimer to to smothly scroll the view downwards or something...

I think you should use NSScrollView's scrollLineDown method to scroll the line down, one line at a time...that might be easier. But you have to subclass...

P.S Try and download AppKido by Andy Lee, its really easy to search apples docs with.

Thanks, I'll experiment with this. If scrollLineDown only goes one line I might have a little trouble there are multiple lines that go out-of-bounds, so to speak, at once. Is there a way to test how much text is beneath and do a for loop?

I just found my other thread, so i will report this one to the moderator for deletion
 
Status
Not open for further replies.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.