UITableView 总结 2020

2020-06-28  本文已影响0人  Look2021
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kAdaptedFloat(20))];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
    }
    return _tableView;
}
#pragma mark ------- UITableViewDelegate -------

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kAdaptedFloat(50);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [UITableViewCell cellForTableView:tableView];
}
//根据cell, 刷新cell
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    [self.tableView reloadRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationNone];

// 用storyboard创建UITableViewController
+ (instancetype)gh_sweepermanagement {
    return [[UIStoryboard storyboardWithName:NSStringFromClass(self) bundle:nil] instantiateViewControllerWithIdentifier:NSStringFromClass(self)];
}

//tableview既要有左滑删除又要有全选删除
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.collectTableView.editing) {
        return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
    }else{
        return UITableViewCellEditingStyleDelete;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *GHHomePageDVcellID = @"GHHomePageDVcellID";
    GHHomePageDVcell *cell = [tableView dequeueReusableCellWithIdentifier:GHHomePageDVcellID];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"GHHomePageDVcell" owner:nil options:nil] firstObject];
    }
    
    return cell;
}
tableViewCell
//cell选中没有效果
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[tableView deselectRowAtIndexPath:indexPath animated:NO];
//改变全选cell,左边的选中颜色
cell.tintColor = [UIColor orangeColor];

//改变cell的背景颜色(选择cell的颜色)
UIView *backgroundViews = [[UIView alloc]initWithFrame:cell.frame];
backgroundViews.backgroundColor = [UIColor whiteColor];
[cell setSelectedBackgroundView:backgroundViews];
上一篇 下一篇

猜你喜欢

热点阅读