使用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;