UITableView的使用

来源:互联网 发布:linux gzip解压命令 编辑:程序博客网 时间:2024/06/04 00:43

使用UITableView的时候必须挂上两个代理协议UITableViewDataSource,UITableViewDelegate

UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT- 70) style:UITableViewStylePlain];

    table.showsVerticalScrollIndicator = NO;

    table.separatorStyle = UITableViewCellSeparatorStyleNone;

    table.delegate = self;

    table.dataSource = self;

    table.backgroundView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"back"]];

    table.backgroundColor = [UIColor blackColor];

[self.view addSubview:table];

常见代理的方法如下:

设置tableView的行数数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

设置tableView显示的内容

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

设置tableView组数

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;  

设置tableView cell的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

设置tableView被选中的时候调用

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;


0 0
原创粉丝点击