TableView Cell - mark specific row as selected when page loads - tableview

Normally when a TableView loads no cell is selected until you touch the screen.
How do I make a particular row be selected? This row is derived from a database.

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
is the method you need.
You can read more about it on Apple's site.
https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/selectRowAtIndexPath:animated:scrollPosition:

Related

NSTableView single click action

How to capture the event of single-clicking on a row of an NSTableView and trigger an action? (Idealy, it should trigger the action for left clicks only, not right clicks, but this is not required.)
Implementing -tableViewSelectionDidChange of the table view's delegate is close to what I want. However, if a row is currently selected, clicking on that row again doesn't call -tableViewSelectionDidChange since the selection didn't change.
Connect the selector action event on the table view (better from interface designed), then
- (IBAction)onAction:(id)sender {
NSTableView* tableView = (NSTableView*)sender;
// use tableView.selectedColumn/tableView.selectedRow to get the selection
}
You can also connect it from code if you want fro viewDidLoad:
[self.tableView setAction:#selector(onAction:)];

NSPopupButton not updating when using setValue:forKey: against it's CoreData bound field

I'm working on a CoreData / Document based app. In one area of the UI I've setup a view-mode table with various columns. One column has an NSPopupButton in it with the Selected Index binding setup as Table Cell View.objectValue.startupState.
Picking any of the menu items in the popup will correctly update the startupState attribute on the entity with the index of the menu item clicked and the NSPopupButton text updates as well. I've verified the attribute value is in fact updated by saving, closing, and re-opening the document.
In another column I have an NSPopupButton bound similarly to another attribute in the same entity - Table Cell View.objectValue.mode. Depending on the mode selection it will modify the startupState value through a manual implementation of setMode which does this statement in certain cases:
[self setValue:[[NSNumber alloc] initWithInt:1] forKey:#"startupState"];
The issue I'm having is that the NSPopupButton isn't updating to show the menu item text for the selected index. As before, I saved, closed, and re-opened the document after the above code ran and the correct item was selected / text appeared so I know the setValue call updated the attribute.
Any ideas?
As mentioned in the comments, Volker's suggestion addresses the issue. willChangeValueForKey and didChangeValueForKey messages are needed around the setValue:forKey call like this:
[self willChangeValueForKey:#"startupState"];
[self setValue:[[NSNumber alloc] initWithInt:1] forKey:#"startupState"];
[self didChangeValueForKey:#"startupState"];

UITableView pushes new UITableView

I have a UTTableView that displays a list of items from an SQLite database. That works great.
I want the user to click on one of the items in the ListView and that pushes a new TableView that shows data on another ListView from the SQLite database.
eg: user selects Apple from the list on TableView_1
I want the new TableView list to display the types of apples. How do I tell the second TableView to populate the list with the types of apples.
any ideas would be great I cant get past this part in my project.
David
You can load the data into the same table again, as Matthisas indicates.
Or you can segue to another UITable (in another View Controller maybe) in which you load the data. It is easy to identify the selected line in
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
So you can do something like:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedFruit=[selectionTableArray objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:#"showDetailsSegue" sender:self];
}

populate UITableView on click

I have a UITableView that parses xml data from a webserver.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// parse data from xml
}
when the view loads, it automatically populates the tablecell, but i dont want it to be like that. I want to populate the table cells only when the user taps a button.
I did something like, hide the table view then show it when the user taps, but i also dont want it to be like that, i want it to only parse and populate the cells when the user taps the button.
Do not set tableView Delegate methods in .xib file. just set them in your view Controller. Then when button is tapped just use reloadData method of tableView.
Hope this will help.

How to save the edited contents of the row in NSTableView?

I added few rows to the tableview and started editing one of the rows (which are inserted in the tableview), while this row is in edit mode, if I perform some action on a button (which is in different view), I would like to save the contents of the previous row and bring the new row into edit mode.
Any pointers to implement the same.
I implemented setObjectValue: for the tableview.
- (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row;**

Resources