【发布时间】:2012-04-02 13:56:50
【问题描述】:
首先,我是 Objective-c 编程的新手,所以我可能在我的代码中犯了一些错误。
这是我所做的:我创建了一个带有一些 xml 的 php 文件,以从我的 MySQL 数据库中获取值。一切都进入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
问题是我在 TableView 中得到的唯一内容是每个单元格中的 {,如下所示:
这是我的 .h :
@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
我的对象很好地连接到我的 TableView 的数据源和委托。我希望这些单元格由我的数据库值填充。
【问题讨论】:
标签: mysql objective-c cocoa nsarray nstableview