Hello world help

Discussion in 'Mac Programming' started by knott, Nov 24, 2009.

  1. knott macrumors newbie

    Joined:
    Nov 24, 2009
    #1
    Hi all, i am new. i have a button A and want to call function B that returns the message "hello".
    Can you please help me, Thank you

    hello.h
    PHP:
    #import <Cocoa/Cocoa.h>

    @interface hello NSObject {
        
    IBOutlet NSTextView *msg;
    }
    - (
    IBAction)button:(id)sender;
    @
    end
    hello.m
    PHP:
    #import "hello.h"

    @implementation hello

    - (IBAction)button:(id)sender {
    --- 
    what should come here? ---
    }

    - (--- 
    what should come here? ---) {
    NSMutableString *msg = [[NSMutableString allocinit];
    NSString *str = [NSString stringWithFormat:@"hello"];
    [
    msg appendString:str];
    return [
    msg autorelease];
    }

    @
    end
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You can name your method whatever you want. Maybe call it "helloText". Using that example, you would first need to declare it in your header file as such:
    Code:
    - (NSString *)helloText;
    Then, plug that into the implementation file:
    Code:
    - (NSString *)helloText
    {
        ... blah blah ...
    }
    To call it, use:
    Code:
    [self helloText];
    If you want to put the method's returned value into your text view, use:
    Code:
    [msg setString:[self helloText]];
     
  3. knott thread starter macrumors newbie

    Joined:
    Nov 24, 2009

Share This Page