Hey i am trying to echo out a an array into a table, i've been using a book on cocoa but think i am going wrong somewhere. Now i know from my nslog that i am filling up the array but its not going into my nstableview.
This is my .m
And this is my .h
In my xib i have a NSTableView that is bound to array controller in the drop down, controller key is section and model key path is userName.
My Array controller is in class mode, with a class name of usersArray and userName is in the key.
This is my .m
Code:
#import "UsersTable.h"
@implementation UsersTable
- (void)userName:(NSMutableArray *)a
{
// Connect to the database
MysqlConnection *connection = [MysqlConnection connectToHost:@"localhost"
user:@"root"
password:@""
schema:@"test_db"
flags:MYSQL_DEFAULT_CONNECTION_FLAGS];
// Fetch the users from the database
MysqlFetch *userFetch = [MysqlFetch fetchWithCommand:@"select username, email from users" onConnection:connection];
NSMutableArray *users; // Create the users array pointer
users = [[NSMutableArray alloc] init]; // Allocate the array to the memory
// Create the userArray for the table
for (NSDictionary *userRow in userFetch.results) {
NSString *user = [userRow objectForKey: @"username"];
[users addObject:user];
}
}
@synthesize userName;
@end
And this is my .h
Code:
#import <Cocoa/Cocoa.h>
#import "MysqlConnection.h"
#import "MysqlCommitException.h"
#import "MysqlRollbackException.h"
#import "GC_MYSQL_BIND.h"
#import "MysqlFetch.h"
#import "MysqlFetchField.h"
@interface UsersTable : NSObject {
NSWindow *window;
NSString *userName;
}
@property (readwrite, copy) NSString *userName;
@end
In my xib i have a NSTableView that is bound to array controller in the drop down, controller key is section and model key path is userName.
My Array controller is in class mode, with a class name of usersArray and userName is in the key.