This seems like it would be an easy thing to do but I am having a lot of trouble getting a button to respond to events while in a CPTableView. Here is the initialization code:
//deleteColumn is hooked up to CIB table column.
[deleteColumn setEditable:YES];
[deleteColumn setWidth:24];
var deleteButton = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
[deleteButton setTarget:self];
[deleteButton setAction:#selector(deleteClicked:)];
[deleteColumn setDataView:deleteButton];
I then have this selector code in the same view controller:
- (void)deleteClicked:(id)sender
{
console.log(sender);
}
It seems the table view is squashing any mouse clicks inside it because I don't get the console log when I click the button.
Is there an easy way to do this? All I want is a button that deletes corresponding row in the table.
The CPTableView takes over the action of the button for its own purposes. Try listening for the regular edit delegate message CPTableViewDataSource:tableView:setObjectValue:forTableColumn:row: in your table delegate.
Related
I'm writing an application for Mac. In NSTableview I set both handler for action and doubleAction.
self.tableView.doubleAction = #selector(tableViewDoubleAction)
self.tableView.action = #selector(tableViewSingleAction)
The problem is every double click the row in table view, it call both 'tableViewDoubleAction' and 'tableViewSingleAction'.
How can I separate it?
Thanks,
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:)];
I have a project where a user fills in a web form, once the user hits submit it moves to a viewcontroller that shows a message "sent" or "error".
How can I make it automatically move to the main view controller without pressing a button, after a certain amount of seconds (so it displays the message "sent" for approx 2 - 3 seconds then moves to the main vc)
Any information would be highly appreciated, thankyou
Sean
You should be able to show the view and, in the viewDidLoad method (or viewDidAppear), set a timer to call a method that dismisses the view controller. Use performSelector:withObject:afterDelay to perform the delay.
Have a look here:
How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?
You can trigger some code inside a block to run after a specified delay. Inside that code you can include your code to navigate to the other view controller.
The code for doing this depends on whether you are using storyboards or not. If you are using storyboards, you can use:
[self performSegueWithIdentifier:#"MySegueName" sender:self];
If you are not using storyboards, you can use the following to display the second view controller modally:
[self presentModalViewController:myNewViewController animated:YES];
Can anyone offer assistance with adding a delete button to a tableview in xcode? I can create the button but cannot get it to delete anything in the table. I'm using the default code that comes with the Master Detail Application but have changed the content of the table using an NSObject.
This should be the default behaviour of the edit button.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
This will allow you to click and delete any item in the list after it is pressed.
Unless I am misunderstanding how you are using the table item list.
BACKGROUND:
I have a tableview with a list of names. When you click on a name in the list, it displays additional detail information in another section of the window. Everything is connected and is working correctly.
However...
I would like to use Type Select with this table and have run into the following snag:
When I start typing a name (while the table is selected) it correctly highlights the appropriate name in the table BUT the detailed information to the right of the table does not change.
I know the reason is the code for changing the detail information is in an IBAction method which is only called when you click to select a name in the list, and uses the [sender clickedRow] call to get the index of the selected name.
I also suspect that I need to use the [tableView selectedRow] (since it is being selected, but you are not clicking on it) but I am not quite certain where or how to perform this check.
I'm also thinking that since "type select" isn't sending an action message, I won't be able to use [sender selectedRow] but rather will use [tableView selectedRow]...
QUESTION:
How can I tell when the selected row in a tableview has changed via type select?
Thanks!
Implement the tableViewSelectionDidChange: delegate method in your controller, and ensure that your controller is the NSTableView's delegate.
You could update your view with something like:
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification {
[relatedView updateInformationFromRow:[[aNotification object] selectedRow]];
}
From the documentation:
tableViewSelectionDidChange: Informs the delegate that the table
view’s selection has changed.
Within that, you would update your related view. You could use the aNotification's object, which will be a NSTableViewSelectionDidChangeNotification, again from the documentation, is:
Posted after an NSTableView object's selection changes. The
notification object is the table view whose selection changed. This
notification does not contain a userInfo dictionary.