首页

#import
//首页
//UIViewController 视图控制器
//带有容器性质的controller(控制器)只能放置UIViewController类型的控制器
@interfaceHomePageViewController : UIViewController
@end


#import "HomePageViewController.h"
#import "QuickEnterTableViewCell.h"
#import "HomePageCourseTableViewCell.h"
#import "EliteSchoolTableViewCell.h"
#import "TeachersOfFamousSchoolTableViewCell.h"
#import "HomePageDataTableViewCell.h"
#import "HomePageHeaderView.h"
//@interface 声明类型,后面<>放的是这个类要实现的代理<代理类型>
@interface HomePageViewController ()
//声明属性(weak 和strong是对对象内容进行描述的)
@property(nonatomic,strong)UITableView* homePageTableView;
@end
@implementationHomePageViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view
CGRectmainScreen=[UIScreenmainScreen].bounds;
//homePageTableView set方法
self.homePageTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, mainScreen.size.width, mainScreen.size.height) style:UITableViewStyleGrouped];
//设置代理,由谁完成
//tableview有两个重要的代理,一个是数据源代理,一个是用来操作的代理
self.homePageTableView.delegate=self;
self.homePageTableView.dataSource=self;


//_homePageTableView get方法
//每一个view都有一个addSubview的方法,用来添加子视图
[self.view addSubview:_homePageTableView];
HomePageHeaderView* headerView = [[HomePageHeaderViewalloc]initWithFrame:CGRectMake(0,0, mainScreen.size.width,160)];
self.homePageTableView.tableHeaderView= headerView;
/*
1.返回值使用
2.static
3.UITableView、UITableViewCell
*/
}
//mark-标记的含义,什么是宏定义
#pragma mark-UITableViewDelegate
//TableView 有多少块,每个块,都可以设置头视图,如果不实现这个方法,默认是一块
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView
{
return 1;
}
//两个代理(这两个代理必须实现)
//代理1:返回有多少行数据
//每一块有1行
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
/* //给第一块返回他的行数
if(section==0)
{
return 1;
}
*/
return 4;
}
//代理2:返回这一行的展示内容样式
//TableView 有复用机制UITableViewCell是被复用的
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
if(indexPath.row==0)
{
static NSString * idf=@"tableleviewcell_Id";
//中括号表示调用方法[对象 空格 方法:参数 空格 方法:参数]
QuickEnterTableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:idf];
if(!cell)
{
cell = [[QuickEnterTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
}
returncell;
}
elseif(indexPath.row==1)
{
static NSString * idf =@"homepageCourseCell_idf";
//tableView dequeueReusableCellWithIdentifier的复用池
HomePageCourseTableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:idf];
if(cell==nil)
{
cell = [[HomePageCourseTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
}
returncell;
}
elseif(indexPath.row==2)
{
static NSString * idf = @"homePageDataTableViewCell_idf";
HomePageDataTableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:idf];
if(cell ==nil) {
cell = [[HomePageDataTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];


}
returncell;
}
elseif(indexPath.row==3)
{
static NSString * idf = @"eliteSchoolTableViewCell_idf";
EliteSchoolTableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:idf];
if(cell==nil)
{
cell = [[EliteSchoolTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
}
returncell;


}
elseif(indexPath.row==4)
{
static NSString * idf = @"teachersOfFamousSchoolTableViewCell_idf";


TeachersOfFamousSchoolTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:idf];
if(cell ==nil) {
cell = [[TeachersOfFamousSchoolTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
}
returncell;


}
return nil;
}
【首页】//返回的类型是CGFloat
//设置cell的高度
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
if(indexPath.row==3) {
return145;
}
else
{
return100;
}


}
//返回header高度的方法
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
return 44;
}
//返回header内容,样式展示为系统的固定样式
//对象类型后一定要加*(除了CGFloat、NSInteger、int、float、double)
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section
{
//@""表示无数据的一个字符串
return @"";
}
//UIView所有视图类的基类
//设置header的自定义视图
- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
UIScreen* mainScreen = [UIScreenmainScreen];
UIView* headerView =[[UIViewalloc]initWithFrame:CGRectMake(0,0, mainScreen.bounds.size.width,44)];


returnheaderView;
}
@end

    推荐阅读