Note that there are some explanatory texts on larger screens.

plurals
  1. PONSTableView Data Source Not Working
    primarykey
    data
    text
    <p>I am trying to populate an NSTableView with an NSArray. I have a view controller, which I have set as my datasource, but every time I run the program, I get this error: <code>Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:</code>, both of which I have implemented. Here is my header:</p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; @interface ChatViewController : NSViewController &lt;NSTableViewDataSource&gt; - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView; - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex; @end </code></pre> <p>And here is my implementation file:</p> <pre><code>#import "ChatViewController.h" #import "Socket.h" @interface ChatViewController () @property (strong) IBOutlet NSTableView *people; @property (strong) IBOutlet NSTextField *message; @property (strong) IBOutlet NSButton *send; @property (strong) Socket *sock; @property (strong, nonatomic) NSString *recievedText; @property (strong, nonatomic) NSArray *tableData; - (void)updateUI; @end @implementation ChatViewController @synthesize sock; @synthesize recievedText; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { [self.people setDataSource:self]; sock = [[Socket alloc] init]; [sock connectToServerWithIP:@"127.0.0.1" andPort:5001]; [self updateUI]; } return self; } - (void)updateUI { [sock sendMessage:@"getPeople"]; recievedText = [NSString stringWithString:[sock recieveMessage]]; self.tableData = [recievedText componentsSeparatedByString:@";"]; NSLog(@"%@", self.tableData); [self.people reloadData]; NSLog(@"%@", self.people); } - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { return [self.tableData count]; } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { return [self.tableData objectAtIndex:rowIndex]; } @end </code></pre> <p><code>Socket</code> is a class that I created for opening and closing sockets to a server, which is fully functional. The <code>tableData</code> array is populated like a normal array.</p> <p>Thanks for any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload