本文实现UITableView一些常用操作
在.h文件中
在.h文件中
@interface FirstViewController(本文件名) : **ViewController<UITableViewDataSource,UITableViewDelegate>{
NSArray *dataArray;
}
NSArray *dataArray;
}
@end
在.m文件中
UITableView *table = [UITableView alloc]initWithFrame:CGRectMake(0, 64, 320, 450)];
table.delegate = self;
table.dataSource = self;
[self.view addSubview:_table];
dataArray = [NSArray arrayWithObjects:@"Iphone5S",@"Iphone6",@"Iphone6 Plus",@"MacBook air",@"MacBook pro", nil];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"UITableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//config the cell
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
}
return cell;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [dataArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 80;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//SecondViewController *second = [[SecondViewController alloc]init];
//跳转
//[self.navigationController pushViewController:second animated:YES ];
}