iOS 开发 Tips

记录在开发过程中的一些小技巧的使用

TableView

取消 table viewsection 悬停

有时候,通过使用 sectionView 实现tableView的间隔效果,但是不想让这个间隔悬停。

1
2
3
4
5
6
7
8
9
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat sectionHeaderHeight = 12;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}

tableView 中有输入框,键盘隐藏 - UITableViewController 的效果

通过实现UITableViewController中控制键盘的效果,又不使用UITableViewController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- (UITableView *)tableView {
if (!_tableView) {

_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
//处理键盘弹出tableView自动像是移动一段距离
UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[self addChildViewController:tvc];
_tableView = tvc.tableView;

_tableView.delegate = self;
_tableView.dataSource = self;

// ...

}
return _tableView;
}

布局

其他

-------------本文结束谢谢欣赏-------------
Alice wechat