0

I am following the OSX tutorial series on developer.apple.com and have run into a problem. When I paste or type text into the NSTextView and try to send it to the general pasteboard, the NSTextView returns a null string. I then tried to see if the NSTextStorage was null and it too is returned as null. Below is the relevant parts of the h and m files.

// Document.m
#import "Document.h"

@implementation Document

@synthesize the_view;   //NSTextView
@synthesize showStuff;  //NSScrollView


- (IBAction)copy2:(id)sender {
  NSLog(@"copying");

  NSTextStorage *ts = [the_view textStorage];
  if( ts )
    NSLog(@"not null");

  NSString *text = [[the_view textStorage] string];

  NSLog(@"%@",text);

  //NSString *text = @"okay";

  NSPasteboard *pb = [NSPasteboard generalPasteboard];
  [pb declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
  [pb setString:text forType:NSStringPboardType];
}

//Document.h
#import <Cocoa/Cocoa.h>

@interface Document : NSDocument
{
  NSTextView *the_view;
}

@property (nonatomic, retain) IBOutlet NSTextView *the_view;

- (IBAction)copy2:(id)sender;

- (IBAction)paste2:(id)sender;

@property (weak) IBOutlet NSScrollView *showStuff;

@end

Above you'll notice I have a commented out version of the string "text" that is set to "okay". If I use that, the word "okay" is placed on the general pasteboard.

So my question is if you can spot any reason why NSTextStorage would be returning null when there is valid text in the NSTextView. Appreciate the help.

Jack Stone
  • 37
  • 1
  • 6
  • 1
    Did you connect your outlets in IB? – uchuugaka May 16 '13 at 00:51
  • I am weak in my understanding of outlets. I did drag a connection between the NSTextView and the header file. Other than that, I don't know what to do in relation to outlets in this context. – Jack Stone May 16 '13 at 01:05
  • To verify outlet connection is done right or not check 'the_view' is nil or not. – Raviprakash May 16 '13 at 04:13
  • After getting uchuugaka's tip, I went and searched for info on outlets, and that led me to make a new test app with several components that talk to each other. Now I have a better understanding of how they work, which leads me to the conclusion that incorrectly connected outlets are the cause of the original problem. – Jack Stone May 16 '13 at 04:31

0 Answers0