Professional Web Applications Themes

Simple Cocoa program - Mac Programming

I am trying to write a simple 'Cocoa Doent-based App', but with th exception of the simple part of making the screen, I can't quite get handle on what to do It has a text box will the user enters a string It has a button, that when pushed, it will get the length of the strin entered and then will print the string entered with the number o characters For example, if you were to type, "frog", it would print, "frog has letters" after the user clicks the button I understand that I am to create a function that ...

  1. #1

    Default Simple Cocoa program

    I am trying to write a simple 'Cocoa Doent-based App', but with th
    exception of the simple part of making the screen, I can't quite get
    handle on what to do
    It has a text box will the user enters a string
    It has a button, that when pushed, it will get the length of the strin
    entered and then will print the string entered with the number o
    characters
    For example, if you were to type, "frog", it would print, "frog has
    letters" after the user clicks the button
    I understand that I am to create a function that once the button i
    pressed will grab the text in the text box and will then print it out to th
    other 'NSTextField.' My problem is that I don't understand how to ge
    the text out of the text box. Each time I step through the code, when
    break on the function where I press the button, the textbox appears t
    be empty
    Any help will be greatly appreciated

    Thanks
    Charle

    ZenBad Guest

  2. #2

    Default Re: Simple Cocoa program

    ZenBad <osx.org> wrote in message news:<TT4Ec.235$tampabay.rr.com>... 

    You have to use the Interface Builder to make links between the screen
    stuff and Outlets, that way when you want the text you can pull it
    from the Outlet in your code. I'm not real good on this myself but go
    here for some really good tutorials.
    (http://www.cocoadevcentral.com/aboutus.php)

    --jim
    Jim Guest

  3. #3

    Default Re: Simple Cocoa program

    >> I am trying to write a simple 'Cocoa Doent-based App', but with the 
    >
    >You have to use the Interface Builder to make links between the screen
    >stuff and Outlets, that way when you want the text you can pull it
    >from the Outlet in your code. I'm not real good on this myself but go
    >here for some really good tutorials.
    >(http://www.cocoadevcentral.com/aboutus.php)
    >
    > --jim
    >.
    >[/ref]
    Very helpful. I will look at it while I am at work today.
    Thanks, Charles

    ZenBad Guest

  4. #4

    Default Re: Simple Cocoa program

    On Tue, 29 Jun 2004, osx.org wrote: 

    Let me recommend the Hillegass book, 2nd edition (uses Xcode). It
    focusses more on the library and how to make things work together than
    on objective C and seems to assume that once you've been through the
    step by step on making those connections, it suffices to say "connect X
    to Y" unless it's something new. For someone who's already a
    programmer, it seems to be great.

    joe
    Joe Guest

  5. #5

    Default Re: Simple Cocoa program

    ZenBad <osx.org> wrote in message news:<TT4Ec.235$tampabay.rr.com>...
     [/ref]

    The 'Currency Converter' demo application and tutorial
    should help you with this. It does just what you want:
    get a string from a text box when the user clicks a button.

    They're on your system (somewhere)...
    On my system here it's at:
    file:///Developer/Doentation/Cocoa/SiteInfo/NewToCocoa.html

    then click on 'Developing Cocoa Objective-C Applications: A Tutorial'

    It's also a PDF at
    file:///Developer/Doentation/Cocoa/ObjCTutorial/objctutorial.pdf

    Let's hope they haven't changed the location too much.
    I guess a trip to the Terminal and a 'locate' would find it, too.

    Good luck!

    (sorry for the silly font... I hoped cut'n'paste would
    drop the formatting).


    Mike Guest

  6. #6

    Default Re: Simple Cocoa program

    In article <local>,
    Joe Davison <net> wrote:
     

    I'll second that. I haven't tried the new edition of Hillegass' book
    yet, but I'm an experienced C programmer to whom the move to Cocoa was
    possible in one weekend with Hillegass' book. And I'm not exceptionally
    smart or anything. The book is that good.

    Cheers,
    -- Uli Kusterer
    http://www.zathras.de
    Uli Guest

  7. #7

    Default Re: Simple Cocoa program

    In article <google.com>,
    net (Jim Schimpf) wrote:
     

    If you have some prior C experience, it helps to think of these lines as
    pointers. You control-drag from the object containing the pointer
    variable to the object you want it to point to. The difference being,
    that IB will automatically create the objects and stuff the pointers in
    the instance variables for you.

    HTH,
    -- Uli Kusterer
    http://www.zathras.de
    Uli Guest

  8. #8

    Default Re: Simple Cocoa program

    The second edition is great, and this question seems to be right from
    one of the challenges in the book....

    On 2004-06-30 07:37:18 -0400, Uli Kusterer <de> said:
     
    >
    > I'll second that. I haven't tried the new edition of Hillegass' book
    > yet, but I'm an experienced C programmer to whom the move to Cocoa was
    > possible in one weekend with Hillegass' book. And I'm not exceptionally
    > smart or anything. The book is that good.
    >
    > Cheers,
    > -- Uli Kusterer
    > http://www.zathras.de[/ref]


    Jon Guest

  9. #9

    Default Re: Simple Cocoa program

    On 2004-06-28 22:56:51 -0400, ZenBad <osx.org> said:
     


    Hey Charles. I am not sure why you would want to do this doents
    based, but anyway...

    First in MyDoent.h you will want:

    {
    IBOutlet NSTextField *nonEditTextField;
    IBOutlet NSTextField *textField;
    }

    - (IBAction)countLetters:(id)sender;

    Or something like that. The the nonEdit is the field you will put the
    text into, the textField is where you'd get the text from...

    In IB you will want to have the object(probably MyDoent) know about
    the text field. You do this by control-dragging from the instance
    variable in the doc window( MyDoent.nib ) to the text field in the
    window and connecting it to textField. Do the same for the
    nonEditTextField. Then you will want to control-drag from the button to
    the instance variable in the doc window to connect the button's action
    to the "countLetters" (or whatever) function. The countLetters function
    only needs to do this:

    if( [[textField stringValue] length] == 0){
    [nonEditTextField setStringValue:"Emtpy string."];
    } else {
    [nonEditTextField setStringValue:
    [NSString stringWithFormat:"% has %d letters.", [textField
    stringValue], [[textField stringValue] length]]];
    }


    If you need anything else just post here or feel free to email...

    Jon

    Jon Guest

Similar Threads

  1. can someone help me with simple flash program??
    By Arias1702 in forum Macromedia Flash Sitedesign
    Replies: 10
    Last Post: July 22nd, 02:46 PM
  2. need help developing a simple drawing program
    By Yammyclause webforumsuser@macromedia.com in forum Macromedia Flash Sitedesign
    Replies: 0
    Last Post: October 7th, 04:19 PM
  3. Cocoa: simple HTML text to Unicode
    By Simon Slavin in forum Mac Programming
    Replies: 3
    Last Post: September 8th, 04:30 PM
  4. Simple question about C program
    By Hugh Kang in forum UNIX Programming
    Replies: 1
    Last Post: July 22nd, 10:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139