Skip to content

Instantly share code, notes, and snippets.

@TheLarkInn
Last active December 29, 2015 08:39
Show Gist options
  • Save TheLarkInn/7645010 to your computer and use it in GitHub Desktop.
Save TheLarkInn/7645010 to your computer and use it in GitHub Desktop.
SimpleTableView
//
// AppDelegate.h
// Bug Viewer
//
// Created by Sean Larkin on 11/25/13.
// Copyright (c) 2013 Sean Larkin. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTableView *bugTicketTable;
@property (assign) IBOutlet NSArrayController *myArrayController;
-(void) populateTable;
-(NSString *)getDataFrom:(NSString *)url;
@end
//
// AppDelegate.m
// Bug Viewer
//
// Created by Sean Larkin on 11/25/13.
// Copyright (c) 2013 Sean Larkin. All rights reserved.
//
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize myArrayController;
@synthesize bugTicketTable;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//populate table with the populateTable method
[self populateTable];
}
-(NSData *)getDataFrom:(NSString *)url
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:url]];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *responseCode = nil;
NSData *oResponseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
if([responseCode statusCode] != 200){
NSLog(@"Error getting %@, HTTP status code %li", url, (long)[responseCode statusCode]);
return nil;
}
return oResponseData;
}
- (IBAction)getTicketFromTT:(id)sender {
}
- (void)populateTable
{
NSData *data = [self getDataFrom:@"http://172.27.13.175/tt_pt_api/api/v1/reports/tied_emr_tickets"];
NSError *error = nil;
NSMutableDictionary *res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
NSArray *array = [res valueForKey:@"reports"];
[[self myArrayController] addObjects:array];
[bugTicketTable reloadData];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment