tableview常用方法

2017-05-08  本文已影响16人  夏日里的夏天
- (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;//设置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];
}

上一篇下一篇

猜你喜欢

热点阅读