重寫scrollView最上方的偏移量(默認向下偏移64)
if([selfrespondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)])
{
//去掉系統默認的偏移
self.automaticallyAdjustsScrollViewInsets=NO;
//獲取tabelView的偏移屬性
UIEdgeInsetsinsets =self.tableView.contentInset;
//設置tableView的偏移屬性值
insets.top=self.navigationController.navigationBar.bounds.size.height;
//設置屬性
self.tableView.contentInset=insets;
self.tableView.scrollIndicatorInsets= insets;
}
self.tableView.frame=CGRectMake(0,20,self.view.bounds.size.width,self.view.bounds.size.height);
ScrollView被忘記的牛逼代理方法【謹記】
-(void)scrollViewWillEndDragging:(UIScrollView*)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inoutCGPoint*)targetContentOffset
{//用來判斷,scrollView是上滑還是下滑
NSLog(@"yyyy == %f? +++? xxxx == %f",velocity.y,velocity.x);
//記錄ScrollView最上方的坐標
NSLog(@"targetContentOffsetyyyy == %f? +++? targetContentOffsetxxxx == %f",targetContentOffset->y,targetContentOffset->x);
//根據值處理navigationBar
if(velocity.y>0)
{
self.navigationController.navigationBar.hidden=YES;
}
else
{
self.navigationController.navigationBar.hidden=NO;
}
設置tableViewcell不讓點擊等各個屬性
DBEmptyTableViewCell* emtyCell = (DBEmptyTableViewCell*)[DBEmptyTableViewCellcellWithTableViewNib:tableView];
emtyCell.message.text=@"還沒有動態哦";
//設置其不能被點擊
emtyCell.userInteractionEnabled=NO;
//設置其沒有點擊效果
emtyCell.selectionStyle=UITableViewCellSelectionStyleNone;
returnemtyCell;
2、設置tableView沒有線條
tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
2、設置tableView某一個cell沒有線條
btncell.separatorInset=UIEdgeInsetsMake(0,0,0, cell.bounds.size.width);
3、設置cell的線條顯示完整
-(void)viewDidLayoutSubviews {
if([_tableViewOnerespondsToSelector:@selector(setSeparatorInset:)]) {
[_tableViewOnesetSeparatorInset:UIEdgeInsetsZero];
}
if([_tableViewOnerespondsToSelector:@selector(setLayoutMargins:)])? {
[_tableViewOnesetLayoutMargins:UIEdgeInsetsZero];
}
}
3、設置cell的線條顯示完整方案2
cell?.separatorInset =UIEdgeInsetsZero
cell?.layoutMargins =UIEdgeInsetsZero
cell?.preservesSuperviewLayoutMargins =false
代理方法:當tableViewcell畫出屏幕時,調用此代理方法
-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPat{
if([cellrespondsToSelector:@selector(setLayoutMargins:)]) {
[cellsetLayoutMargins:UIEdgeInsetsZero];
}
if([cellrespondsToSelector:@selector(setSeparatorInset:)]){
[cellsetSeparatorInset:UIEdgeInsetsZero];
}}
判斷tableView向上滑還是向下滑 ?笨方法方法
//加載scrollView和滑動都會執行此方法
- (void)scrollViewDidScroll:(UIScrollView*)scrollView
{
//******判斷向上滑動還是向下滑動******
int_lastPosition =0;
intcurrentPostion = scrollView.contentOffset.y;
if(currentPostion - _lastPosition >50) {
_lastPosition = currentPostion;
[UIViewanimateWithDuration:0.2animations:^{
//NSLog(@"向上滑動");
self.menu.hidden=NO;
_headView.frame=CGRectMake(_headRect.origin.x,_headRect.origin.y-(_headRect.size.height-40),deviceWidth,_headRect.size.height);
_scrollView.frame=CGRectMake(0,_scrollViewRect.origin.y-(_headRect.size.height-40),deviceWidth,_scrollViewRect.size.height+200);
}];
}
elseif(_lastPosition - currentPostion >35)
{
_lastPosition = currentPostion;
[UIViewanimateWithDuration:0.2animations:^{
self.menu.hidden=YES;
//??????????????? //NSLog(@"向下滑動");
_headView.frame=_headRect;
_scrollView.frame=_scrollViewRect;
}];}}}
處理tableView.tableFooterView添加控件問題點擊無效等
//先定義一個View作為tableViewFootView【防止直接添加控件超出范圍】
UIView* myView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,80)];
myView.backgroundColor= [UIColoryellowColor];
_tableView.tableFooterView= myView;//讓myView作為_tableView.tableFooterView
//定義一個控件,現在myView就作為_tableView.tableFooterView了,正常使用,不會在出現控件超出范圍問題了
UIButton* btn = [UIButtonbuttonWithType:UIButtonTypeCustom];
btn.backgroundColor= [UIColorredColor];
btn.frame=CGRectMake(0,20,self.view.bounds.size.width,40);
[btnsetTitle:@"點擊"forState:UIControlStateNormal];
[btnaddTarget:selfaction:@selector(btnClick)forControlEvents:UIControlEventTouchUpInside];
[myViewaddSubview:btn];
設置tableView局部刷新
//一個section刷新
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//一個cell刷新
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
設置UITableView的滾動條顏色
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
讓UITableView的Cell不重用,解決方案
-?(UITableViewCell?*)tableView:(UITableView?*)tableView?cellForRowAtIndexPath:(NSIndexPath?*)indexPath
{
NSString?*CellIdentifier?=?[NSString?stringWithFormat:@"Cell%d%d",
[indexPath?section],?[indexPath?row]];//以indexPath來唯一確定cell
UITableViewCell?*cell?=?[tableView?dequeueReusableCellWithIdentifier:CellIdentifier];//出列可重用的cell
if(cell?==?nil)?{
cell?=?[[UITableViewCell?alloc]?initWithStyle:UITableViewCellStyleDefault?reuseIdentifier:CellIdentifier];
}
}
如何設置Plain 風格下UITableView的Section的HeaderView不在UITableview上浮動
CGFloat?dummyViewHeight?=40;
UIView?*dummyView?=?[[UIView?alloc]?initWithFrame:CGRectMake(0,0,?self.tableView.bounds.size.width,?dummyViewHeight)];
self.tableView.tableHeaderView?=?dummyView;
self.tableView.contentInset?=?UIEdgeInsetsMake(-dummyViewHeight,0,0,0);
修改tableViewCell選中狀態的顏色
cell.selectedBackgroundView= [[UIViewalloc] initWithFrame:cell.frame];cell.selectedBackgroundView.backgroundColor= [UIColorwhiteColor];
點擊cell單元格的時候取消選中單元格
-(void)tableView:(UITableView*)tableViewdidSelectRowAtIndexPath:(NSIndexPath*)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES];?}