[iOS开发] TableView
Dynamic TableView的使用方法
1 设置TableView的delegate和dataSource(TableView has two important @propertys: its delegate and its dataSource. )
2 声明实现这两个Delegate <UITableViewDelegate, UITableViewDataSource>
3 UITableView dataSource protocol必须实现3个方法
1) section的数目
2)section中row的数目
3)cell的具体内容
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return section_rows;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return cell_rows;
}
// 自定义TableCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Custom Table Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}
//自定义header
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
SectionHeader *header = [[SectionHeader alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, HEADER_HEIGHT)];
return header;
}
//header高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return HEADER_HEIGHT;
}
//cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [CustomCell cellHeight];
} 相关推荐
heqiang0 2020-06-25
Terminator0 2020-02-19
WintonTalks 2012-07-16
莫封洛 2019-07-26
ssddgkke 2019-06-30
我的iOS王者之路 2019-06-28
Rephontil 2015-08-10
NineYao 2015-01-30
SoccerZZM 2012-10-15
NineYao 2012-07-16
Terminator0 2019-11-11
lijiexiaoge 2019-06-29
jscjxysx 2019-06-26
Jplane 2019-06-26
Jplane 2019-06-20
Physhy 2014-10-04