UITableView 那些事

最新更新:
是不是常常遇到,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

1.jpg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容