美文网首页
MyTableView

MyTableView

作者: 你的小福蝶 | 来源:发表于2017-11-01 09:51 被阅读16次

XCode自带的Code Snippet Libray(代码仓库)是非常方便的工具,当然最近几个版本拖入有些问题,这里分享一下最常用的TableView Code,不断完善中勿喷


Code Snippet Library Code Snippet Library
<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)NSMutableArray *dataArray;

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.estimatedRowHeight = 300.0f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.backgroundColor = [UIColor whiteColor];
}

- (UITableView *)tableView{
    if (!_tableView) {
        CGSize windowsRect = [UIScreen mainScreen].bounds.size;
        CGRect tableRect = CGRectMake(0, 0, windowsRect.width, windowsRect.height);
        _tableView = [[UITableView alloc]initWithFrame:tableRect style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.bounces = YES;
        _tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        //_tableView.separatorStyle = UITableViewCellAccessoryNone;
        [_tableView setSeparatorInset:UIEdgeInsetsZero];
        [_tableView setSeparatorColor:RGB(240, 240, 240)];
        [_tableView setLayoutMargins:UIEdgeInsetsZero];
        
        
        [self.view addSubview:_tableView];
        
        _tableView.mj_header.automaticallyChangeAlpha = YES;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self reFreshData];
        }];
        _tableView.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
            [self loadMore];
        }];
    }
    return _tableView;
}

- (void)reFreshData{
    
}

- (void)loadMore{
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return <#expression#>
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return <#expression#>
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"<#expression#>";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

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

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}


相关文章

网友评论

      本文标题:MyTableView

      本文链接:https://www.haomeiwen.com/subject/oyswpxtx.html