-3

This method found in the AppDelagate, loads a text file of my choosing and splits the context of the text file into an array.

Im having trouble displaying the contents of the array in my NSScrollview * called self.textView.

I am not sure how to update the text view with each member of the array.

- (IBAction)loadButton:(id)sender {        
    NSOpenPanel *panel = [NSOpenPanel openPanel];
    if ([panel runModal] == NSFileHandlingPanelOKButton) {
        NSURL *bookUrl  = [panel URL];
        NSString *contents = [NSString stringWithContentsOfURL: bookUrl encoding: NSASCIIStringEncoding error: NULL];
        NSArray *loadedBook = [contents componentsSeparatedByString:@"#NP#"];
        self.textView.value = loadedBook[0];            
    }
}
Daniel
  • 20,420
  • 10
  • 92
  • 149

1 Answers1

1

The right method is setString:, which is declared in NSText.

your code should be:

- (IBAction)loadButton:(id)sender {        
    NSOpenPanel *panel = [NSOpenPanel openPanel];
    if ([panel runModal] == NSFileHandlingPanelOKButton) {
        NSURL *bookUrl  = [panel URL];
        NSString *contents = [NSString stringWithContentsOfURL: bookUrl encoding: NSASCIIStringEncoding error: NULL];
        NSArray *loadedBooks = [contents componentsSeparatedByString:@"#NP#"];
        [self.textView setString:bookStr];
    }
}

UPDATE

Take a look at this question, to see how to add text to a NSScrollView

Community
  • 1
  • 1
Daniel
  • 20,420
  • 10
  • 92
  • 149