UITableViewCell使用小结

来源:互联网 发布:泓樽付是网络传销吗 编辑:程序博客网 时间:2024/06/07 02:23

#pragma mark - tableView的数据源方法,和代理方法

/** 每个分组的数据行数,如果分组返回不同的行数可以用switch来做,如果单个列表直接返回想要的行数 */

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

{

    return 0;

}

/** 返回单元格的明细,通过索引的section和row来确定*/

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

{

    return nil;

}

/** 分段显示数据,可以分段或单列表形势 */

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

    return 5;

}

#pragma mark - tableView的委托方法
/** 设置cell每行间隔的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 0) {

        return 180;

    }else if (indexPath.section == 1){

        return 120;

    }else if(indexPath.section == 4){

        if (indexPath.row == 0) {

            return 35.0;

        }else{

            return 100.0;

        }

    }else{

        return 70.0;

    }    

}

/** 设置分组标题内容宽度 */

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

    if (section == 0) {

        return 1;

    }else{

        return 5;

    }

}

/** 设置尾部说明内容宽度 */

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

    return 5;

}

/** 设置分组标题头前的view */

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

    UIView *headerView = [[UIView allocinitWithFrame:CGRectMake(00, SCREENHEIGHT, 10)];

    headerView.backgroundColor = RGB(239239244);

    return headerView;

}

/** 设置分组标题尾的view */

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

    UIView *footerView = [[UIView allocinitWithFrame:CGRectMake(00, SCREENWIDTH, 0)];

    footerView.backgroundColor = RGB(239239244);

    return footerView;

}

/** 行点击 */

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section ==3) {

        NSString *urlStr =  [[GetUrlString sharedManager]urlWithHotQueueWebData];

        JFHotQueueViewController *hotQueueVC = [[JFHotQueueViewController alloc]init];

        hotQueueVC.urlStr = urlStr;

        [self.navigationController pushViewController:hotQueueVC animated:YES];

    }else if(indexPath.section ==4){

        if (indexPath.row !=0) {

            JFRecommentModel *recommendModel = _recommentArray[indexPath.row-1];

            JFShopDetailViewController *shopDetailVC = [[JFShopDetailViewController alloc]init];

            shopDetailVC.shopID   =[recommendModel.id stringValue];

            [self.navigationController pushViewController:shopDetailVC animated:YES];            

        }

    }    

}

/*设置标题尾的名称*/

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    if (section == 0)

    {

        return @"标题尾1";

    }

    else

    {

        return @“标题尾";      

    }

}

/*设置标题头的名称*/

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    if (section == 0) {

        return @"标题头1";

    }

    else

        return @"标题头2";

}


0 0
原创粉丝点击