Skip to content

Instantly share code, notes, and snippets.

@musawirali
Last active December 25, 2015 20:39
Show Gist options
  • Save musawirali/3fbf24e116f0899f175d to your computer and use it in GitHub Desktop.
Save musawirali/3fbf24e116f0899f175d to your computer and use it in GitHub Desktop.
Typical view controller with a simple table
@interface ViewController ()
@property (strong, nonatomic) NSArray * items;
@end
@implementation ViewController
@synthesize items = _items;
- (NSArray *)items
{
if (!_items)
_items = @[@"Item1", @"Item2", @"Item3", @"Item4"];
return _items;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"];
}
cell.textLabel.text = [self.items objectAtIndex:indexPath.row];
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (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