Created
August 30, 2013 06:38
-
-
Save vincent178/6386875 to your computer and use it in GitHub Desktop.
UITableViewDataSource Code Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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