0

I am making a simple gui on Xcode. I use a button to load a text file into an NSArray like below.

NSOpenPanel *panel = [NSOpenPanel openPanel];
if ([panel runModal] == NSFileHandlingPanelOKButton) {        

    albumURL = [panel URL];
    info = [NSString stringWithContentsOfURL: albumURL encoding: NSASCIIStringEncoding error: NULL];
    listItems = [info componentsSeparatedByString:@"\n"];        
    NSString *combinedString = [listItems componentsJoinedByString:@"\n"];

    //[self.TrackList setValue:combinedString forKey: combinedString];
}

I want to print the contents of the array into the NSscrollview as a series of strings. I also want to print the context of some specific index into different textfields.

So far I only managed to figure out how to put a set string into the textfield like below.

[self.myTextField setStringValue:@"My string of whatever"];

I'm new to this stuff so if you need more info please ask.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
Lee
  • 5
  • 4
  • You can't put text directly into a scroll view. You have to add other UIView objexpctz to the scrollview. Perhaps you want to use a UItextView rather that a scroll view? – Paulw11 May 12 '17 at 12:18
  • Also you have tagged iOS but you are referring to NSScrollView and NSTextField - are you Using iOS or macOS? – Paulw11 May 12 '17 at 12:22
  • @Paulw For now I am thinking about about using a wrapping label instead for multiline text. I still don't know how to print my array of strings into such a place though. macOS sorry. – Lee May 12 '17 at 12:23
  • You don't "print it". You have to add your text field as the content view of the scrollview and set the text field text property, but simply using an `NSTextView` and disabling editing will give you a scrolling text window much more easily. – Paulw11 May 12 '17 at 12:25
  • @Paulw ok thanks so I will forget the scrollview for now. How do I iterate the array and print each line into a text view? – Lee May 12 '17 at 12:30
  • Take a look at `NSTableView` or `NSTextView`. – Willeke May 12 '17 at 12:31
  • Just build a combined string the way you have shown and set it as the new text storage http://stackoverflow.com/questions/15527305/proper-way-to-replace-nstextstorage-in-nstextview but a tableview may also be more appropriate as @Willeke suggested – Paulw11 May 12 '17 at 12:35
  • @Paulw That works to print out the whole array as a string. But I want to print out only certain indexes. For instance ignore index 0 and 1 then print out 2 to the end. And other textviews will print out indexes 0 and 1 separately. – Lee May 12 '17 at 12:38

0 Answers0