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

knott

macrumors newbie
Original poster
Nov 24, 2009
4
0
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 alloc] init];
NSString *str = [NSString stringWithFormat:@"hello"];
[msg appendString:str];
return [msg autorelease];
}

@end
 
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]];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.