tableview常用方法

- (void )viewDidLoad {
    [super viewDidLoad];
self.navigationController.navigationBar.barTintColor = TitleCOLOR;
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:16],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.view.backgroundColor = [UIColor whiteColor];
    //自定義返回按鈕
    UIBarButtonItem*backItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(backBtn:)];
    self.navigationItem.leftBarButtonItem=backItem;

    // Do any additional setup after loading the view.
    
    self.myTableView.delegate= self;
    self.myTableView.dataSource = self;
    self.myTableView.tableFooterView =[[UIView alloc] initWithFrame:CGRectZero];//刪除多余的cell分割線
    
    self.myTableView.backgroundColor = BGCOLOR;
    [self.myTableView registerNib:[UINib nibWithNibName:@"" bundle:nil] forCellReuseIdentifier:@""];
    //    self.myTableView.separatorStyle= UITableViewCellSeparatorStyleNone;//去除分割線
    
    //這個去除分割線方法必須寫在注冊cell的后面。
    
}




-(IBAction)backItem:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 12;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
    static NSString * strCell = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:strCell];
    if(!cell){
            cell = [[UITableViewCell alloc] initWithStyle:0 reuseIdentifier:strCell];
        }
    cell.textLabel.text = @" 來自夏日里的夏天的Xcode";
    cell.textLabel.numberOfLines= 0;
    cell.textLabel.font = [UIFont systemFontOfSize:15.0f];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//設(shè)置cell的箭頭
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section==0?0:8;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
    self.myTableView.estimatedRowHeight= 44.0f;
    return UITableViewAutomaticDimension;
}
// 改變UITableView的headerView背景顏色為透明色


- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
    view.tintColor = [UIColor clearColor];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
    [self.myTableView deselectRowAtIndexPath:indexPath animated:YES];
}

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

推薦閱讀更多精彩內(nèi)容