Skip to content

Instantly share code, notes, and snippets.

@vincent178
Created August 30, 2013 06:38
Show Gist options
  • Save vincent178/6386875 to your computer and use it in GitHub Desktop.
Save vincent178/6386875 to your computer and use it in GitHub Desktop.
UITableViewDataSource Code Sample
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSInteger result = 0;
if ([tableView isEqual:self.myTableView]) {
result = 3;
}
return result;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger result = 0;
if ([tableView isEqual:self.myTableView]) {
switch (section) {
case 0: {
result = 3;
break;
}
case 1: {
result = 5;
break;
}
case 2: {
result = 8;
break;
}
}
}
return result;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *result = nil;
if ([tableView isEqual:self.myTableView]) {
static NSString *tableViewCellIdentifier = @"MyCells";
result = [tableView dequeueReusableCellWithIdentifier:tableViewCellIdentifier];
if (result == nil) {
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewCellIdentifier];
}
result.textLabel.text = [NSString stringWithFormat:@"Section %ld, Cell %ld", (long)indexPath.section, (long)indexPath.row];
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment