Прежде всего, я новичок в Objective-C программировании, поэтому я, вероятно, допустил некоторые ошибки в своем коде.
Вот что я сделал: я создал файл php с некоторым xml для получения значений из моей базы данных MySQL.Все идет в NSArray в target-C.Если я смотрю на журнал, все работает нормально, потому что он показывает мои массивы со всеми строками и столбцами 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 - это {
вкаждая ячейка выглядит так:
![Table View example image](https://i.stack.imgur.com/iGOkD.png)
Вот мой .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.Я хочу, чтобы эти ячейки были заполнены значениями моей базы данных.