开发学习笔记--UItableView

来源:互联网 发布:闲鱼淘宝介入流程 编辑:程序博客网 时间:2024/05/22 12:24
本文实现UITableView一些常用操作


在.h文件中

@interface FirstViewController(本文件名) : **ViewController<UITableViewDataSource,UITableViewDelegate>{
    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 ];
    
}
0 0
原创粉丝点击