- (void)viewDidLoad {
[superviewDidLoad];
self.title=@"管理圈子";
self.tableView= [[UITableViewalloc]initWithFrame:CGRectMake(0,64,MSW,MSH)style:UITableViewStyleGrouped];
self.tableView.delegate=self;
self.tableView.dataSource=self;
self.tableView.backgroundColor= [UIColorredColor];
[self.viewaddSubview:_tableView];
}
今天寫項目的時候遇到這樣一個問題丛楚,導(dǎo)航欄距離tableview頂部還有一定高度
如圖所示
究其原因吟吝,有2個點
1.上網(wǎng)查了各種資料最后總結(jié)下來時因為創(chuàng)建UITableViewgrouped模式就是這樣诈铛,這是ios的自帶樣式,所以才會導(dǎo)致導(dǎo)航欄距離tableview頂部還有一定高度焚挠,最后把UITableViewgrouped改為UITableViewStylePlain
2.self.automaticallyAdjustsScrollViewInsets=NO;//scrollview預(yù)留空位 ?
沒有寫這一句,這一點很重要,漏寫了還是會想上圖一樣的錯誤
正確代碼如下:
- (void)viewDidLoad {
[superviewDidLoad];
self.title=@"管理圈子";
self.tableView= [[UITableViewalloc]initWithFrame:CGRectMake(0,64,MSW,MSH)style:UITableViewStylePlain];
self.tableView.delegate=self;
self.tableView.dataSource=self;
self.tableView.backgroundColor= [UIColorredColor];
[self.viewaddSubview:_tableView];
self.automaticallyAdjustsScrollViewInsets=NO;//scrollview預(yù)留空位
}
最后發(fā)效果展示圖:圖上的cell還沒有做適配嫡纠,比較丑,請忽略
最后延赌!歡迎加入iOS技術(shù)大群除盏,學(xué)習(xí)知識交更多的同行朋友? ? ? ? ? ? QQ群號:580284575