How do I reset a table view? - xcode

I have a table view in an iPhone xcode tab bar application that shows data either alphabetically or numerically, depending on a user selected option in one of the tabs. It works for the most part, but when I change the option and then go back into the table view, the table view initially looks like it did before the option was changed. However, as new cells get scrolled into view, they have the new display mode.
I can identify when the option changes, but I can't seem to get the code correct that would re-initialize the cells such that the next time they come into view they have the correct values. The data comes from a static array with set values, so I don't want to do anything with the data source, just the table view.
In other words, once the display option changes, I want to wipe out the table view I have so that the next time the table view displays it will show the correct data right from the start rather than after scrolling occurs.
Any help would be appreciated. Thanks.

It sounds like you want to call reloadData on the TableView.
[yourTableView reloadData];

Related

NSTableView textfield cell should not go into edit on click

I have two NSTableViews in my app and both are set up the same, same parameters, etc., they have several columns with NSTextField cells and the first column is editable.
The first table behaves like I want it: if the user clicks, the row is selected. If the user clicks the row a second time the textfield goes into edit mode, letting the user change the text in it.
The second table should act the same but it doesn't: if I click a row in it, most of the time it goes straight into edit mode with the textfield. Very, very rarely this does not happen.
Does anyone know what causes this? I checked all parameters (in IB) and code and they are the same on both tables. If I set 'Refuses first responder' on the textfield in the naughty table, it doesn't let me edit the textfield at all so that option doesn't help.
SOLVED IT! The reason why it works on the first table view but caused the edit issue on the second table was because the first table allows dragging while the second did not! It seems somehow this interferes with doubleAction (I even read somewhere that an editable table cannot have doubleAction but it seems to work without problems). I could fix it by implementing tableView(_:writeRowsWithIndexes:toPasteboard:) in the second tableview's view controller and simply return false (since the 2. table should not have drag'n'drop ability) ...
func tableView(aTableView:NSTableView, writeRowsWithIndexes rowIndexes:NSIndexSet, toPasteboard pboard:NSPasteboard) -> Bool
{
return false;
}

NSTableView as a form - nextKeyView issue (or how to force load all rows)

Perhaps using an NSTableView as a form is a terrible idea, but I've got it working pretty well in every respect except that you can't tab from field to field.
I have a table with a label column and a field column. I also have an array that keeps track of each row in the table with its accompanying NSTextField control. The controls are set in the array as they are loaded during tableView(tableView: viewForTableColumn: row:).
After the tableview is drawn, I run through each control in the array and set its nextKeyView to the following control.
This works swell, BUT only for those controls which have been displayed on screen. Because the control isn't added until it's loaded, table rows which are off-screen aren't hooked up.
My current approach (which is awful) is to manually scroll the table several times in order to force everything to load, then set all the nextKeyViews. I haven't got it working very well yet, so I was hoping someone had a better idea. Force-loading all views, if it works, should be an OK solution, but there may be something smarter out there too.
I guess the answer is
table.scrollRowToVisible(<row>)
This will show the row you want to see.

mouseOver for NSTableView

I have NSTableView in my application and i have added the hovering effect for the rows by using HoverTableDemo.
I can get the hovering effect only for one row in my table.
It is not apply for the whole table.
How can i get Hovering effect for full table.
Can any body have any idea please revert me.
Take a look: https://stackoverflow.com/a/464828/1758762
You're on the right track with -mouseEntered: and -mouseExited:.
Look into NSView's -addTrackingRect:owner:userData:assumeInside: and -removeTrackingRect: methods.
I can get the hovering effect only for one row in my table.
You can either set up your tableView to create trackingRects for every row that's in there whenever the contents of the tableView change, or alternatively, set up/update one tracking area on the entire tableView whenever -tile or another layout related method is called.

RootViewController need to resort/reload data array xcode 4.3

I'm implementing an example, in that example, I read in data from a database, put it in an array, sort it, and it's displayed using the RootViewController. The DB read and array load happen before the RVC code. So, it works, I get the data in the window created by the RVC and there's a nav controller there as well.
I want to add a button or something to the nav controller so that when you hit it, it sends a value back to the RootViewController.m file, then based on that value, I want to resort the array and display it once again in the RootViewController window.
I'm not sure how to do this. What changes would I have to make to the .xib and the RootViewController.m file?
Please, I'm a confused nube. %-0 Thank you very much.
There's a fair amount to this, so I'll give some general points and if any of them cause problems, it may be easier to work out smaller details.
In you RVC's viewDidLoad method, you can create a button and set it as the right or left button in your controller's navigationItem.
You can associate a tap on that button with a method in your controller that can do whatever you want when the button is tapped. (But a button doesn't send values, really, so you may have to explain more about that idea.)
I assume the RVC has a table view if you're showing array contents, so once the array (mutable array, I'd assume) is re-sorted, you can tell the table view to reload its data.
In answer to your secondary question, once you have resorted your array (or generally updated your data however you wish) you can force the table view to reload programmatically
[tableView reloadData];
Where 'tableView' is your instance variable pointing to your table view

Have an NSTableView row always stay in the same place

Im trying to make a trash can system in my app. I have a NSTableView and a trash can row. I want to have the row "stick" to the bottom of the visible table view so it can always be seen. Is it possible to do this and if not is there a better approach to doing this?
Thanks for any help
Sit another utterly separate UIView, on top the views that contain the table.
Simply fake it up to make it look like a row from the table.
As you say, "Thanks that sounds like it will work as long [tableview deselectRow:[tableview selectedRow] works so it appears that the fake row is really in the view." -- that is precisely what you do.
There's no supported way to do this and it might be near impossible. You might try embedding your "main" table view in a container NSView (that observes the table view's frame changes resizes / performs layout when the size changes). This view would leave room at the bottom for a single-row table view with no headers. You could feed the "main" table view all but the sticky row, and feed only the sticky row to the smaller table.

Resources