Skip to content

Instantly share code, notes, and snippets.

@jonathontoon
Created February 21, 2014 17:19
Show Gist options
  • Save jonathontoon/9138750 to your computer and use it in GitHub Desktop.
Save jonathontoon/9138750 to your computer and use it in GitHub Desktop.
TableView Homework
//
// AppDelegate.h
// HomeworkTableView
//
// Created by Jonathon Toon on 2/20/14.
// Copyright (c) 2014 Jonathon Toon. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// HomeworkTableView
//
// Created by Jonathon Toon on 2/20/14.
// Copyright (c) 2014 Jonathon Toon. All rights reserved.
//
#import "AppDelegate.h"
#import "NotificationsViewController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
NotificationsViewController *notificationsViewController = [[NotificationsViewController alloc] init];
UINavigationController *appNavBarController = [[UINavigationController alloc] initWithRootViewController:notificationsViewController];
[[appNavBarController navigationBar] setBarTintColor:[UIColor colorWithRed:0.157 green:0.318 blue:0.643 alpha:1.0]];
[tabBarController setViewControllers:@[appNavBarController]];
[[self window] setRootViewController:tabBarController];
[[appNavBarController navigationBar] setBarStyle:UIBarStyleBlackTranslucent];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
//
// NotificationCell.h
// HomeworkTableView
//
// Created by Jonathon Toon on 2/21/14.
// Copyright (c) 2014 Jonathon Toon. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NotificationCell : UITableViewCell
@property (strong, nonatomic) NSString *actorName;
@property (strong, nonatomic) NSString *contextString;
@property (strong, nonatomic) NSDate *timeStamp;
@property (strong, nonatomic) UILabel *notificationString;
@property (strong, nonatomic) UIImage *actorImage;
@property (strong, nonatomic) UILabel *timePassed;
@end
//
// NotificationCell.m
// HomeworkTableView
//
// Created by Jonathon Toon on 2/21/14.
// Copyright (c) 2014 Jonathon Toon. All rights reserved.
//
#import "NotificationCell.h"
@implementation NotificationCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
CGRect cellFrame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 80);
[self setFrame:cellFrame];
CGRect imageFrame = CGRectMake(12, 6, 68, 68);
UIView *imageView = [[UIView alloc] initWithFrame:imageFrame];
[imageView setBackgroundColor:[UIColor redColor]];
[self addSubview:imageView];
}
return self;
}
-(void)layoutSubviews{
[super layoutSubviews];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
}
@end
//
// NotificationsViewController.h
// HomeworkTableView
//
// Created by Jonathon Toon on 2/20/14.
// Copyright (c) 2014 Jonathon Toon. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface NotificationsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
//
// NotificationsViewController.m
// HomeworkTableView
//
// Created by Jonathon Toon on 2/20/14.
// Copyright (c) 2014 Jonathon Toon. All rights reserved.
//
#import "NotificationsViewController.h"
#import "NotificationCell.h"
@interface NotificationsViewController ()
@property UITableView *notificationsTableView;
@end
@implementation NotificationsViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"init");
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.notificationsTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
[[self view] addSubview:[self notificationsTableView]];
[[self notificationsTableView] setDelegate:self];
[[self notificationsTableView] setDataSource:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
# pragma mark - UITableView Methods
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NotificationCell *cell = [[NotificationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
return cell;
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment