得到:
*** 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 行和 5 个“hello world”时,显然没有任何反应。帮助