Skip to content

Instantly share code, notes, and snippets.

@conniec
Created July 13, 2011 19:11
Show Gist options
  • Save conniec/1081073 to your computer and use it in GitHub Desktop.
Save conniec/1081073 to your computer and use it in GitHub Desktop.
c
@import "globals.j"
//@import "WordsController.j"
@implementation LessonsController : CPObject
{
JSObject objs @accessors;
JSObject dataObject;
@outlet CPScrollView lessonsScrollView;
@outlet CPTableView lessonsTableView;
@outlet CPLabel appLabel;
@outlet CPPopUpButton appName;
//WordsController wordsController;
}
- (id)init
{
if(self = [super init])
{
objs = [@"test", @"test2"];
objs = [];
[self getLessons];
[lessonsTableView setBackgroundColor:[CPColor colorWithHexString:@"CCDDDD"]];
[lessonsScrollView setBackgroundColor:[CPColor colorWithHexString:@"CCDDDD"]];
//wordsController = [[WordsController alloc] init];
console.log(@"FINAL", objs);
}
return self;
}
- (IBAction)addLesson:(id)aSender
{
alert(@"add a lesson!");
}
- (IBAction)removeLesson:(id)aSender
{
alert(@"remove");
}
- (IBAction)editLesson:(id)aSender
{
alert(@"edit");
}
- (void)getLessons
{
var request = [CPURLRequest requestWithURL:requestLessonURL];
//[[CPURLConnection alloc] initWithRequest:request delegate:self];
console.log(@"5", objs);
}
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
{
//objs = CPJSObjectCreateWithJSON(data);
dataObject = CPJSObjectCreateWithJSON(data);
console.log(@"1", dataObject);
console.log(@"2", objs);
objs = dataObject;
console.log(@"3", objs);
[[CPNotificationCenter defaultCenter]
postNotificationName:reloadLessonsNoti object:nil];
console.log(@"4", objs);
}
- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPString)error
{
alert(error) ;
}
- (int)numberOfRowsInTableView:(CPTableView)tableView
{
return [objs count];
}
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
{
return objs[row];
}
- (void)tableViewSelectionDidChange:(CPNotification)aNotification
{
if(lessonView === [aNotification object]){
var i = [[[aNotification object] selectedRowIndexes] firstIndex];
[wordsController getWord:[[lessonsController objs] objectAtIndex:i]];
//[searchField setStringValue:@""];
}
else{
var i = [[[aNotification object] selectedRowIndexes] firstIndex];
if(i > -1){
var row = [[wordsController objsToDisplay] objectAtIndex:i];
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment