Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect outlet in a table cell view?

I am using a view-based table, and I want to create an outlet for an element in a cell view. I cannot get the outlet to connect though... it's always nil.

Specifically, I have a NSProgressIndicator in a table cell and want to manipulate it in code.

Here's what I have so far:

I have created a subclass of NSTableView, with the corresponding outlet property:

@interface MyTableCellView : NSTableCellView
@property IBOutlet NSProgressIndicator *myProgressIndicator;
@end

@implementation MyTableCellView
-(void)awakeFromNib
{
    // _myProgressIndicator is nil!
}
@end

And I have set the custom class in the nib. The existing NSTableCellView is replaced with MyTableCellView via the dropdown.

At this point, some observations:

  • If I Ctrl+Click and drag the progress indicator to connect this outlet, it is not shown. enter image description hereenter image description here

  • Likewise, if I try to Ctrl+Click and drag the progress indicator using the assistant editor, I can only connect to the property via binding. It doesn't recognize this as a valid outlet. enter image description here

  • However this outlet IS shown on the sidebar, with a warning that it doesn't exist: enter image description here

  • I know MyTableCellView is being used. Breakpoint on awakeFromNib confirms this, and confirms that _myProgressIndicator is nil.

This is a sandbox project, with barely more than what I've described.

SO, how do I access this progress indicator from code?

like image 456
tenfour Avatar asked Jan 15 '14 11:01

tenfour


People also ask

How do I add a prototype cell to UITableView?

Choose iOS -> Source -> Cocoa Touch Class. Name the class TableCiewController and make it a subclass of UITableViewController. Go to the TableViewController. swift file and declare the following array.


1 Answers

I don't believe you should do it that way; instead:

  1. Modify the model object used by the table view's data source to populate the table view.
  2. Call the table view reloadData (or better reloadDataForRowIndexes:columnIndexes:).

Therefore you should only need an outlet to the table view to do this and any modification of the table view's cell objects should be done within the table view delegate and/or data source methods.

like image 85
trojanfoe Avatar answered Sep 29 '22 11:09

trojanfoe