Reputation: 4282
Getting :
*** Illegal NSTableView data source (<NSApplication: 0x101602bc0>). Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:
Code .h
//
// AppDelegate.h
// MySQL
//
// Created by - on 10/12/12.
// Copyright (c) 2012 - Software. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> {
NSMutableArray *tabelle_totali;
IBOutlet NSTableView *tabella_tabelle_totali;
IBOutlet NSTableView *tabella_contenitore;
}
@property (assign) IBOutlet NSWindow *window;
//Metodo per scaricare dati
- (void) download_tabelle ;
//Manipolazione tabelle ricevute
- (void)tabelle_ricevute:(NSData *)tabelle;
//Refresh tabella
- (IBAction)refresh_tablelle:(id)sender;
//Refresh tabelle
- (int)numberOfRowsInTableView:(NSTableView *)aTableView;
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
@end
Code .m
//
// AppDelegate.m
// MySQL
//
// Created by - on 10/12/12.
// Copyright (c) 2012 Alberto Bellini Software. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self download_tabelle];
[tabella_tabelle_totali reloadData];
}
- (void) download_tabelle {
NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://*********************.php"];
//inizializzazione richiesta url
NSURL *url = [NSURL URLWithString:databaseURL];
//Richiesta asincrona per richiedere dati
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *tabelle, NSError *error)
{
[self tabelle_ricevute:tabelle];
}
];
}
- (void)tabelle_ricevute:(NSData *)tabelle
{
NSString *response = [[NSString alloc] initWithData:tabelle encoding:NSUTF8StringEncoding];
NSArray *tmpResp = [response componentsSeparatedByString:@"####"]; //This array splits the response string
NSLog(@"%@",response);
//Aggiungo le mie tabelle al mio array
[tabelle_totali addObjectsFromArray:tmpResp];
}
- (IBAction)refresh_tablelle:(id)sender {
//Cancello vecchi dati
while([[tabella_tabelle_totali tableColumns] count] > 0) {
[tabella_tabelle_totali removeTableColumn:[[tabella_tabelle_totali tableColumns] lastObject]];
}
NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:@"1"];
[column setWidth:143];
[[column headerCell] setStringValue:@"*******"];
[tabella_tabelle_totali addTableColumn:column];
[tabella_tabelle_totali reloadData];
}
-(NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
return 5;
}
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
return @"hello world";
}
@end
Sorry lot of code is written in italian, but the issue is "international".. Why do i get this error ? The table dataSource is connected to the File's owner and the outlets as well.. When running the app instead of displaying 5 rows with 5 "hello world", obviously nothing happens.. Help
Upvotes: 2
Views: 1676
Reputation: 1083
When using Swift, the issue may be that the data source class has not explicitly implemented the NSTableViewDataSource
protocol. In particular, with the API renaming in Swift 3, it appears to be the protocol that causes the mapping of the Swift 3 syntax tableView(_:objectValueFor:row:)
to the Objective-C selector tableView:objectValueForTableColumn:row:
.
I discovered this when implementing a table view data source; although I had implemented the correct methods in Swift, I got the *** Illegal NSTableView data source
message at runtime. I was confused until I realized I had forgotten to include the protocol conformance in my class declaration.
Upvotes: 0
Reputation: 6036
The problem may be in your xib file containing your table view. Have you set the table view's delegate to the File's Owner (which would be an instance of NSApplication), or have you set its delegate to your application delegate? It needs to be set to your application delegate.
If you haven't set up an object (visible in the margin to the left of your UI layout) representing your application delegate, you should do so, and connect your table view's delgate connection to that.
Upvotes: 3