Created
April 21, 2011 05:24
-
-
Save agiletalk/933763 to your computer and use it in GitHub Desktop.
Two UITableView in One UIViewController
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
#pragma mark - | |
#pragma mark Table view data source | |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
return 1; | |
} | |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
NSInteger rows; | |
if(tableView == aTable) rows = [aList count]; | |
if(tableView == bTable) rows = [bList count]; | |
return rows; | |
} | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
static NSString *CellIdentifier = @"TwoTablesCell"; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if(cell == nil) { | |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; | |
} | |
// Configure the cell... | |
if(tableView == aTable) | |
cell.textLabel.text = [aList objectAtIndex:indexPath.row]; | |
if(tableView == bTable) | |
cell.textLabel.text = [bList objectAtIndex:indexPath.row]; | |
return cell; | |
} | |
#pragma mark - | |
#pragma mark Table view delegate | |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSString *__title, *__message; | |
if(tableView == aTable) { | |
__title = @"aTable"; | |
__message = [aList objectAtIndex:indexPath.row]; | |
} | |
if(tableView == bTable) { | |
__title = @"bTable"; | |
__message = [bList objectAtIndex:indexPath.row]; | |
} | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:__title message:__message delegate:nil cancelButtonTitle:@"확인" otherButtonTitles:nil]; | |
[alert show]; | |
[alert release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What if the TableViews are to use two different custom UITableViewCell?