Skip to content

Instantly share code, notes, and snippets.

@calebhicks
Created February 21, 2015 18:06
Show Gist options
  • Save calebhicks/df4b2c666f3e998d3b75 to your computer and use it in GitHub Desktop.
Save calebhicks/df4b2c666f3e998d3b75 to your computer and use it in GitHub Desktop.
Using NSEnum to Label Sections
//
// ViewController.m
// UIColorCategory
//
// Created by Caleb Hicks on 2/21/15.
// Copyright (c) 2015 DevMountain. All rights reserved.
//
#import "ViewController.h"
typedef NS_ENUM(NSInteger, TableViewSection) {
TableViewSectionMental,
TableViewSectionEmotional,
TableViewSectionSpiritual,
TableViewSectionTemporal,
TableViewSectionPhysical,
};
@interface ViewController () <UITableViewDataSource>
@property (strong, nonatomic) UITableView *tableView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewSection section = indexPath.section;
switch (section) {
case TableViewSectionEmotional: {
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = @"Emotional";
return cell;
break;
}
case TableViewSectionMental:{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = @"Mental";
return cell;
break;
}
case TableViewSectionPhysical: {
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = @"Physical";
return cell;
break;
}
case TableViewSectionSpiritual:{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = @"Spiritual";
return cell;
break;
}
case TableViewSectionTemporal:{
UITableViewCell *cell = [UITableViewCell new];
cell.textLabel.text = @"Temporal";
return cell;
break;
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
TableViewSection tableViewSection = section;
switch (tableViewSection) {
case TableViewSectionEmotional: {
return 4;
break;
}
case TableViewSectionMental:{
return 3;
break;
}
case TableViewSectionPhysical: {
return 7;
break;
}
case TableViewSectionSpiritual:{
return 3;
break;
}
case TableViewSectionTemporal:{
return 1;
break;
}
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return TableViewSectionPhysical + 1;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment