- (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];
}
tableview常用方法
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
推薦閱讀更多精彩內(nèi)容
- #pragma mark - < UITableViewDelegate> //點擊Cell時調(diào)用函數(shù) - (vo...
- 我們經(jīng)常用到的代理方法,大多是tableView必須的實現(xiàn)的,這里這幾個可選的,但用來處理一些小細(xì)節(jié)是非常方便的。...
- 一、cell的重用機制 1、why同樣的cell會被創(chuàng)建很多次,這樣很浪費系統(tǒng)的內(nèi)存,既然是一樣的,就可以拿來重復(fù)...
- tableView可以說是每個app中必不可少的控件,所以掌握流暢度優(yōu)化技能相當(dāng)?shù)闹匾?這里總結(jié)一些常用的優(yōu)化技...