You need two NSTextViews, or a NSTextView and an NSTextField for one-line only comments. The bottom NSTextView is marked as read-only. You also need an object responsible for keeping track of the text, which should be connected to both NSTextViews. It will have an IBAction which is attached to the button. When the button is pressed, it will take the content of the editable text view and append it to the read-only text view s textStorage. It will also append newlines so the next comment is separated. I am not sure if that will automatically redisplay the text view or if you need to call setNeedsDisplay manually. You may also want to set the content of the editable text view to the empty string in this method.
例IBAction:
- (IBAction)addComment:(id)sender {
NSString *string = [editableTextView string]; //stringValue if using NSTextField
string = [string stringByAppendingString:@"
"];
[[commentTextView textStorage] appendAttributedString:[[[NSAttributedString alloc] initWithString:string] autorelease]];
[commentTextView setNeedsDisplay:YES];
[editableTextView setString:@""];
}