MyTableView

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;
}


最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容