2

取得 :

*** Illegal NSTableView data source (<NSApplication: 0x101602bc0>).  Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:

コード.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

コード.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

申し訳ありませんが、多くのコードがイタリア語で書かれていますが、問題は「国際的」です。なぜこのエラーが発生するのですか?テーブルdataSourceは、ファイルの所有者とアウトレットにも接続されています。5つの「helloworld」で5行を表示する代わりにアプリを実行すると、明らかに何も起こりません。ヘルプ

4

2 に答える 2

3

問題は、テーブルビューを含むxibファイルにある可能性があります。テーブルビューのデリゲートをファイルの所有者(NSApplicationのインスタンス)に設定しましたか、それともそのデリゲートをアプリケーションデリゲートに設定しましたか?アプリケーションデリゲートに設定する必要があります。

アプリケーションデリゲートを表すオブジェクト(UIレイアウトの左側の余白に表示されます)を設定していない場合は、設定して、テーブルビューのデリゲート接続をそれに接続する必要があります。

于 2012-12-11T00:53:26.903 に答える
0

NSTableViewDataSourceSwiftを使用する場合、問題はデータソースクラスがプロトコルを明示的に実装していないことである可能性があります。特に、Swift 3でのAPIの名前変更では、Swift3構文tableView(_:objectValueFor:row:)をObjective-CセレクターにマッピングするのはプロトコルのようtableView:objectValueForTableColumn:row:です。

これは、テーブルビューのデータソースを実装するときに発見しました。Swiftで正しいメソッドを実装しましたが、*** Illegal NSTableView data source実行時にメッセージを受け取りました。クラス宣言にプロトコルの適合性を含めるのを忘れていることに気付くまで、私は混乱していました。

于 2016-10-06T17:37:37.797 に答える