Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created November 8, 2012 03:59
Show Gist options
  • Save ChrisRisner/4036700 to your computer and use it in GitHub Desktop.
Save ChrisRisner/4036700 to your computer and use it in GitHub Desktop.
ios day 13
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSDictionary *item =[itemsArray objectAtIndex:[indexPath row]];
cell.textLabel.text = [item objectForKey:@"name"];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSDictionary *item =[itemsArray objectAtIndex:[indexPath row]];
if ([indexPath row] < 12)
cell.textLabel.text = [item objectForKey:@"name"];
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSDictionary *item =[itemsArray objectAtIndex:[indexPath row]];
UILabel *labelOne = (UILabel *)[cell viewWithTag:1];
UILabel *labelTwo = (UILabel *)[cell viewWithTag:2];
labelOne.text = [item objectForKey:@"name"];
labelTwo.text = [(NSNumber*)[item objectForKey:@"id"] stringValue];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Row tapped at %i", [indexPath row]);
}
NSArray *itemsArray;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSDictionary *itemOne = @{ @"name" : @"item one", @"id" : @1};
NSDictionary *itemTwo = @{ @"name" : @"item two", @"id" : @2};
NSDictionary *itemThree = @{ @"name" : @"item three", @"id" : @3};
NSDictionary *itemFour = @{ @"name" : @"item four", @"id" : @4};
NSDictionary *itemFive = @{ @"name" : @"item five", @"id" : @5};
NSDictionary *itemSix = @{ @"name" : @"item six", @"id" : @6};
NSDictionary *itemSeven = @{ @"name" : @"item seven", @"id" : @7};
NSDictionary *itemEight = @{ @"name" : @"item eight", @"id" : @8};
NSDictionary *itemNine = @{ @"name" : @"item nine", @"id" : @9};
NSDictionary *itemTen = @{ @"name" : @"item ten", @"id" : @10};
NSDictionary *itemEleven = @{ @"name" : @"item eleven", @"id" : @11};
NSDictionary *itemTwelve = @{ @"name" : @"item twelve", @"id" : @12};
NSDictionary *itemThirteen = @{ @"name" : @"item thirteen", @"id" : @13};
itemsArray = [[NSMutableArray alloc] initWithObjects:itemOne, itemTwo,
itemThree, itemFour, itemFive, itemSix, itemSeven, itemEight,
itemNine, itemTen, itemEleven, itemTwelve, itemThirteen, nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [itemsArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment