• 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
Re: Hiding Rows in NSTableView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hiding Rows in NSTableView


  • Subject: Re: Hiding Rows in NSTableView
  • From: Frank Midgley <email@hidden>
  • Date: Mon, 18 Apr 2005 16:32:55 -0500

On Apr 18, 2005, at 1:13PM, Jason Taylor wrote:

I am writing a program that has a table of items, each with a check box. If the check box is checked off, the item is considered complete, like an item of a todo list. The user has the option to hide checked off items when displaying the table. My code is setup such that when a user checks off an item, the object at the row that was checked off is set to 'completed'. When the table is reloaded, the items that are checked off will not show up. In the tableView: objectValueForTableColumn:row datasource method, I check each object of my data source array to see if it is 'completed'. If it is not, I display it, otherwise I don't. The problem is that once I hide an item, the row indexes of the table no longer match the row indexes of my data source array (for instance hiding the first item in the table with row index 0 will hide the object in my data source array with index 0, this is fine, but when the table is reloaded that first element of the data source array is not displayed so the object at row index 0 in the table is actually the object at index 1 in my array). Is there a way to just hide a row in an NSTableView or will I have to subclass it? Does anyone know of any code that does this so I can use it as a reference?

Once a table view has asked how many rows are in the table then that is how many rows will be displayed. It assumes there is a one-to-one mapping between the rows and the entries in the data source.


Two options:

1. Make your data source methods smart enough to hide the hidden rows. For example, the tableView:objectValueForTableColumn:row can't just get the object at the specified row index from the data source. It will have to manually walk through the array (or whatever it is) and count how many visible items it comes across. Since the data source methods get called a lot, a faster implementation that pre-calculated the row index to array index mapping for all possible rows would be much better.

2. Only include the visible rows in your data source. When the user chooses to only show the uncompleted items then remove the completed ones from the data source and store them in a separate container (array, dictionary, whatever). Replace them when the user toggles the setting back. Far simpler coding then the previous option.

-Frank

------------------------------------
Frank M. Midgley
email@hidden
http://homepage.mac.com/knarf/

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Hiding Rows in NSTableView
      • From: Jason Taylor <email@hidden>
References: 
 >Hiding Rows in NSTableView (From: Jason Taylor <email@hidden>)

  • Prev by Date: Re: Strange problem when not declaring the functions in interface
  • Next by Date: Re:[SOLVED] NSBundle won't release ? [by NOT using NSBundle]
  • Previous by thread: Re: Hiding Rows in NSTableView
  • Next by thread: Re: Hiding Rows in NSTableView
  • Index(es):
    • Date
    • Thread