• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
setting tab stops in a document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

setting tab stops in a document


  • Subject: setting tab stops in a document
  • From: Boyd Collier <email@hidden>
  • Date: Fri, 4 Jun 2010 22:09:43 -0700

In an application I'm working on, I read in plain text files containing data to be analyzed.  This uses a slightly-modified version of MyDocument.m that is produced as a result of starting a project with the template for NSDocument architecture.  The modification that I made was to add a method named updateView, which is called near the end of windowControllerDidLoadNib and loadDataRepresentation: ofType:

My reason for adding this method is to make the spacing of tabs something that works well for the sort of data files being analyzed, which presume tabs are used to separate values being analyzed.  Here's the code:

- (void)updateView {
	DBOut(@"updateView was called from MyDocument");

	[[self textView] setString:[self string]];

	// code to set tab stops, as suggested by PGM
	int cnt;
	int numStops = 200;
	int tabInterval = 80;
	NSTextTab *tabStop;

	NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init]; //attributes for attributed string of TextView

	NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];

	[paraStyle setTabStops:[NSArray array]];  // clear all tab stops

	// now put in tab stops at desired intervals
	for (cnt = 0; cnt < numStops; cnt++) {
		tabStop = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:tabInterval*(cnt+1)];
		[paraStyle addTabStop:tabStop];
		[tabStop release];
	}

	[attrs setObject:paraStyle forKey:NSParagraphStyleAttributeName];
	[paraStyle release];

	[[textView textStorage] addAttributes:attrs range:NSMakeRange(0, [[[textView textStorage] string] length])];
	[attrs release];
}


When my application opens a text file, the insertion point is blinking immediately after the last character on the last line.  If I then hit the tab key, the insertion point moves over the correct distance.  However, if I hit the return key when the file is first opened, the insertion point moves to the start of the next line; if I then hit the tab key the insertion point moves it over too few spaces (presumably the default distance rather than what I tried to set in the above code).

What am I missing?

Boyd_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: setting tab stops in a document
      • From: "Paul Sanders" <email@hidden>
    • Re: setting tab stops in a document
      • From: Ross Carter <email@hidden>
  • Prev by Date: detecting touch and hold vs touch in UIButton
  • Next by Date: Re: setting tab stops in a document
  • Previous by thread: Re: detecting touch and hold vs touch in UIButton
  • Next by thread: Re: setting tab stops in a document
  • Index(es):
    • Date
    • Thread