最新更新:
是不是常常遇到,tableview 中有輸入框的需求,你會(huì)怎么做,直接修改tableview 的y, scroll to某一index? 給大家說(shuō)一個(gè)可精準(zhǔn)定位滾動(dòng)位置的方法: textfield 成為焦點(diǎn)時(shí),會(huì)觸發(fā)他的代理方法:
<pre><code>
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//獲取當(dāng)前輸入的textfield,在tableview 的位置
CGPoint pointInTable = [textField.superview convertPoint:textField.frame.origin toView:_detailTableView];
if (pointInTable.y > (ScreenHeight-KeyboardHeight)) {
CGPoint contentOffset = _detailTableView.contentOffset;
contentOffset.y = (pointInTable.y - textField.inputAccessoryView.frame.size.height);
[_detailTableView setContentOffset:contentOffset animated:YES];
}
}
</code></pre>
就是這么簡(jiǎn)單!!!
1,設(shè)置UITableView分割線從頂端開(kāi)始
<pre><code>
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
</code></pre>
2,設(shè)置UITableView空白數(shù)據(jù)多余的分割線
<pre><code>
_tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
</code></pre>
3,當(dāng)UITableViewCell 使用autoLayout之后,我們知道UILabel設(shè)置numberOfLines 為0 時(shí),UILabel 可以自動(dòng)換行.那么問(wèn)題來(lái)了,自動(dòng)換行之后,cell的高度也會(huì)變,如何計(jì)算cell的高度呢? 有一個(gè)高大上的方法:
在cell 中調(diào)用可直接返回它的size
<pre><code>
CGSize size = [self.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
</code></pre>
4,UITableViewCell的xib中也可以設(shè)置分割線的Inset
