I suspect that you'll need to write code to
a) Append text to the bottom of the text field and scroll it into view
b) Erase the text in the text entry field
Thats all the code I have. I guess you could make an array controller, and have the output text view changed to a list view, and then adding an entry/scrolling to the bottom would be easy, but selecting text wouldn't work as expected.
My implementation:
ExampleController.h:
Code:
#import <Cocoa/Cocoa.h>
@interface ExampleController : NSObject {
IBOutlet NSTextView *textOutput;
IBOutlet NSTextField *textInput;
}
- (IBAction) button_add:(id)sender;
- (void) appendString:(NSString *)str;
@end
ExampleController.m:
Code:
#import "ExampleController.h"
@implementation ExampleController
- (IBAction) button_add:(id)sender
{
NSLog(@"event: button_add: %@", sender);
[self appendString:textInput.stringValue];
[self appendString:@"\n"];
[textInput setStringValue:@""];
}
- (void) appendString:(NSString *)str;
{
NSRange endRange;
endRange.location = [[textOutput textStorage] length];
endRange.length = 0;
[textOutput replaceCharactersInRange:endRange withString:str];
endRange.length = [str length];
[textOutput scrollRangeToVisible:endRange];
}
@end
Thanks everyone who had a crack at this, I'll post up the next exercise today
