iOS UITableView 1

来源:互联网 发布:淘宝大学官方视频教程 编辑:程序博客网 时间:2024/06/06 23:16
1     ==================================创建

#pragma -mark创建tableView

- (void)createTableView{

     = [[UITableViewalloc]initWithFrame:self.bounds];

     [selfaddSubview:];

    .backgroundColor= [UIColor clearColor]; 

    .delegate= self;

    .dataSource= self;

    .rowHeight = 120;

}

2   =======================代理

2.1==============通用方法

#pragma -mark  cell number

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


    return
10;

}

#pragma -mark  cell

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

   
UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"cinema_cell"];

    if(cell ==
nil){

        cell = [[
UITableViewCellalloc]init];
    }

    cell.
backgroundColor= [UIColorclearColor];

    return  cell;

}


2.2=================================XIB

#pragma -mark  cell number       

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

   
NSString *month =_moviecomingsAllkeysArray[section];

   
NSArray *movies =_moviecomingsModelDic[month];

    return movies.
count;

}

#pragma -mark  cell                    ======== 注意两个cell 

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

   
WillPlayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"willplay_cell"];

    if(cell ==
nil){

        cell = [[[
NSBundle mainBundle]loadNibNamed:@"WillPlayTableViewCell"owner:niloptions:nil]lastObject];

        cell.
backgroundColor = [UIColor clearColor];
    }

   
NSString *month =_moviecomingsAllkeysArray[indexPath.section];

   
NSArray *movies =_moviecomingsModelDic[month];

   
MovieComingsModel *model = movies[indexPath.row];

    cell.
model = model;

    return cell;
}


2.3================storyBoard  tbaleViewControl   控件根据tag值确定
  
UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"friedList_cell"forIndexPath:indexPath];



3   ======================================== 关于组的方法

#pragma -mark tableView组的头视图     

- (
UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section{

   
UIImageView*_headerTableView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,WidthOfScreen,30)];

    _headerTableView.
image= [UIImageimageNamed:@"topmenu_tab_bg.png"];

   
UILabel*_mouthLabel = [[UILabelalloc]initWithFrame:_headerTableView.bounds];

    [_headerTableView
addSubview:_mouthLabel];

    _mouthLabel.
font= [UIFontsystemFontOfSize:20];

    _mouthLabel.
textColor= [UIColorwhiteColor];

   //加载数据      

   
NSString*month = _moviecomingsAllkeysArray[section];

   
NSLog(@"%@",month);

    _mouthLabel.
text= [NSStringstringWithFormat:@"  %@",month];

//    _mouthLabel.text = month;     == 不一定是String型的

    return _headerTableView;
}



#pragma -mark设置组头的高       

- (
CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section{

    return
30;
}

#pragma -mark 设置组数           

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

    return
_moviecomingsAllkeysArray.count;

}


5   ==========================头视图

_willPalyTableView.tableHeaderView= _headView;




0 0
原创粉丝点击