Cocoa question....

Discussion in 'General Mac Discussion' started by altivec 2003, Jul 9, 2003.

Thread Status:
Not open for further replies.
  1. altivec 2003 macrumors regular

    Joined:
    Feb 8, 2003
    Location:
    Texas
    #1
    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.
     
  2. Fukui macrumors 68000

    Fukui

    Joined:
    Jul 19, 2002
    #2
    Re: Cocoa question....

    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.
     
  3. altivec 2003 thread starter macrumors regular

    Joined:
    Feb 8, 2003
    Location:
    Texas
    #3
    Re: Re: Cocoa question....

    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?
     
  4. altivec 2003 thread starter macrumors regular

    Joined:
    Feb 8, 2003
    Location:
    Texas
    #4
    Re: Re: Cocoa question....

    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
     
Thread Status:
Not open for further replies.

Share This Page