tableView 设置使用宏定义

//去掉多余的分割线

#define TABLEVIEW_FOOTER(tableView)\

\

[tableView setTableFooterView:[[UIView alloc]initWithFrame:CGRectZero]];

// 自适应高度

#define TABLEVIEW_AUTOHIGHT(tableView,HIGHT)\

\

tableView.rowHeight = UITableViewAutomaticDimension;\

tableView.estimatedRowHeight = HIGHT;


// table 注册cell

#define TABLEVIEW_REGISTER_CELL(tableView,ident)\

\

[tableView registerNib:[UINib nibWithNibName:ident bundle:[NSBundle mainBundle]] forCellReuseIdentifier:ident];

/**  tableView背景图 用图片名 */

#define TABLEVIEW_BACK_IMAGENAME(tableView,imageName)\

UIImageView *backImageView=[[UIImageView alloc]initWithFrame:tableView.bounds];\

[backImageView setImage:[UIImage imageNamed:imageName]];\

tableView.backgroundView=backImageView;


/**  tableView背景图 用图片*/

#define TABLEVIEW_BACK_IMAGE(tableView,image)\

UIImageView *backImageView = [[UIImageView alloc]initWithFrame:tableView.bounds];\

[backImageView setImage:image];\

tableView.backgroundView = backImageView;

#define K_WEAK_SELF                 __weak __typeof(&*self)weakSelf = self

// -——————————————————————————————————————————————————————————————————————————————————————————

#import "MJRefresh.h"

#import "MJExtension.h"

static NSString *ident = @"Cell";

<

UITableViewDelegate,

UITableViewDataSource

>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic,assign)NSInteger curPageIdx;

@property (nonatomic,strong)NSMutableArray *arr;

#pragma mark ————————— 设置tableView —————————————

- (void)addUpAndDown{

    

    TABLEVIEW_AUTOHIGHT(_tableView, 50);

    TABLEVIEW_REGISTER_CELL(_tableView, ident);

    TABLEVIEW_REGISTER_CELL(_tableView, ident2);

    TABLEVIEW_FOOTER(_tableView);

    



    [self httpQueryMasterInfo];

    

    

    K_WEAK_SELF;

    _tableView.mj_header= [MJRefreshNormalHeader headerWithRefreshingBlock:^{

        weakSelf.curPageIdx = 1;

        

        //        [weakSelf httpQueryMasterInfo:weakSelf.albumId];

        [weakSelf.tableView.mj_header endRefreshing];

        [weakSelf.tableView.mj_footer endRefreshing];

    }];

    

    

    // 上拉刷新

    _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{

        if ( weakSelf.curPageIdx < -1 ) {

            weakSelf.curPageIdx = 1;

        }

        //        [weakSelf httpQueryMasterInfo:weakSelf.albumId];

        [weakSelf.tableView.mj_header endRefreshing];

        [weakSelf.tableView.mj_footer endRefreshing];

    }];

}


#pragma mark ————————— 分页加载数据 —————————————

- (void)updatePagesData:(NSArray*)newData page:(NSInteger)pageIdx{

    

    if ( newData == nil || newData.count <= 0 ){

        return;

    }

    self.curPageIdx = pageIdx;

    if ( pageIdx == 1 ){

        [_arr removeAllObjects];

        _arr = [NSMutableArray arrayWithArray:newData];

    } else {

        [_arr addObjectsFromArray:newData];

    }

    

    NSLog(@"刷新数据");

    [_tableView reloadData];

}

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

    return 2;

}


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

    return 1;

}

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

        iTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];

        //    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        

        Home *h = [[Home alloc]initWithDictionary:_arr[indexPath.row]];

        [cell.iamgeVIews sd_setImageWithURL:h.headImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

            

        }];

        

        return cell;

}

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

    [tableView deselectRowAtIndexPath:indexPath animated:NO];

}






猜你喜欢

转载自blog.csdn.net/saw471/article/details/79348407