使用UITableView
原来要用IOS的Table
不一定建立UITableViewController直接在UIViewController上就建立UITabelView就可以
当然要也要在.h中添加
<UITableViewDelegate,UITableViewDataSource>
以下部分代码片段
- (void)viewDidLoad { [super viewDidLoad]; myTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 43, 320, 480)]; [myTableView setDelegate:self]; [myTableView setDataSource:self]; [self.view addSubview:myTableView]; }
//定义cell大小 -(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 85; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.imageView.image=[UIImage imageNamed:[imageArr objectAtIndex:[indexPath indexAtPosition:1]]]; } // Configure the cell... return cell; }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Create and push another view controller. /* <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; // ... // Pass the selected object to the new view controller. [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; */ AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; switch ([indexPath indexAtPosition:1]) { case 0: [appDelegate displayView:5]; break; case 1: [appDelegate displayView:6]; break; case 2: [appDelegate displayView:7]; break; } }