使用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;
本文详细介绍了如何在iOS开发中使用UITableView,并重点阐述了必须挂载的两个代理协议UITableViewDataSource和UITableViewDelegate。文章提供了设置tableView行数、显示内容、组数、高度以及选中行为的具体方法。
905

被折叠的 条评论
为什么被折叠?



