get value of selected row NSTableView
how can i 开发者_如何学JAVAget value of selected row in NSTableView?
By using selectedRow
, see here:
@property(readonly) NSInteger selectedRow;
The index of the last selected row (or the last row added to the selection).
You may also be interested in:
–selectedRowEnumerator (deprecated)
–numberOfSelectedRows
–selectedRowIndexes "returns an index set containing the indexes of the selected rows"
Cocoa follows the Model-View-Controller design pattern, so your reasoning as well as your own designs should as well.
You don't get any values from the table because you already have them in your model. Your controller (usually the data source) asks the table for its selected row index(es), then asks your model for the objects matching those indexes, then does whatever it needs to do.
Assuming that you already have property named tableView and in xib you defined tableView with row cellName
NSInteger row = [tableView selectedRow];
NSTableColumn *column = [tableView tableColumnWithIdentifier:@"cellName"];
NSCell *cell = [column dataCellForRow:row];
NSLog(@"cell value:%@", [cell stringValue]);
To get selected row from table try this..
[tableView selectedRow];
To access the tableView value
[array objectAtIndex:[tableView selectedRow]];
In Swift2.0, this could help you:
func tableViewSelectionDidChange(notification: NSNotification) {
let selectedTableView = notification.object as! NSTableView
print(selectedTableView.selectedRow)
}
As we have all the value in our model, so we can only get the index of row and get the value using index. for e.g:
NSInteger row = [self.nsTableView selectedRow]; //here @property (weak) IBOutlet NSTableView *nsTableView;
NSString *cellValue = ObjectValue[row];// NSMutableArray *ObjectValue;
NSLog(@"%@", cellValue);
精彩评论