まず、私は客観的なプログラミングに慣れていないので、おそらく私のコードでいくつかの間違いを犯したでしょう。MySQLからNSTableViewへのNSArray
ここで私がしたことは次のとおりです。私はいくつかのxmlを使ってPHPデータベースファイルを作成しました。すべてがobjective-CのNSArrayに入ります。私は、ログを見れば、それはこのようなすべてのMySQLの行と列と私の配列を示しているので、すべてが正常に動作します:
2012-04-02 08:20:14.822 POS[64632:707] (
{
CPU = 0;
TPS = "(null)";
TVQ = "(null)";
consigne = 0;
coutantQuantiteRecue = 0;
description = "";
nom = "";
prixProduit = 0;
quantiteRecue = 0;
stock = 0;
},
{
CPU = 768;
TPS = "(null)";
TVQ = "(null)";
consigne = 0;
coutantQuantiteRecue = 0;
description = "";
nom = hhh;
prixProduit = 0;
quantiteRecue = 0;
stock = 0;
},
2012-04-02 08:20:14.836 POS[64632:707] The number of rows is:2
問題は、私は私のテーブルビューに入る唯一のことは、このような各セルの{
であるということです:ここでは
@interface InventoryManagement : NSObject<NSApplicationDelegate, NSTableViewDataSource>
{
IBOutlet NSTableView* inventoryTable;
NSArray* m_items;
}
-(int)numberOfRowsInTableView:(NSTableView *)inventoryTable;
-(id)tableView:(NSTableView *)inventoryTable objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex;
-(void)dealloc;
@property (retain) NSArray* m_items;
@end
そして、ここに私の.mファイルです:
@implementation InventoryManagement
@synthesize m_items;
-(id)init
{
[super init];
NSInteger index = 0;
NSString *urlString = [NSString stringWithFormat:@"http://localhost:8888/php/getProducts.php?index=%d&", index];
m_items = [NSArray arrayWithContentsOfURL:[NSURL URLWithString: urlString]];
NSLog(@"%@", [m_items description]);
[m_items retain];
[inventoryTable reloadData];
return self;
}
-(int)numberOfRowsInTableView:(NSTableView *)inventoryTable
{
NSLog(@"The number of rows in fullResult is:%i", [m_items count]);
return [m_items count];
}
-(id)tableView:(NSTableView *)inventoryTable objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex
{
return [m_items objectAtIndex:rowIndex];
}
-(void)dealloc
{
[m_items release];
[super dealloc];
}
@end
私のオブジェクトは、DataSourceと私のTableViewの代理人によく接続しています。これらのセルを自分のデータベース値で埋めるようにします。
あなたは正しいです。私はそれを認識しませんでした。私はそれを試して、後で私の結果を掲載するつもりです。ありがとう! –
私が実際にしたことは、 "for"ループを作成し、各列セルを文字列[]に挿入し、それらの文字列を配列[]に挿入することです。 –