iOS:tableView不得不了解的屬性

今天閑來無事總結(jié)了一下:tableView中用到的比較多的屬性
可能只需要修改一下,就省下很多行代碼:

//這句話不顯示多余的單元格
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

// 這句話不顯示單元格之間的分割線
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;


// 這句話在單元格的最后顯示一個(gè)箭頭
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;


//--- 點(diǎn)擊cell的時(shí)候 cell不會產(chǎn)生高亮狀態(tài) ---
cell.selectionStyle = UITableViewCellSelectionStyleNone;


// --- 寫在viewdidload里面cell自適應(yīng)高度 ----
tableView.rowHeight = UITableViewAutomaticDimension; // 自適應(yīng)單元格高度
 tableView.estimatedRowHeight = 50; //先估計(jì)一個(gè)高度

// 去掉UItableview headerview黏性(sticky)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 40;
    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);
    }
}

// 獲取手勢點(diǎn)擊的是哪一個(gè)cell的坐標(biāo)
NSIndexPath *indexPath = [self.tableView indexPathForCell:((UITableViewCell *)longPress.view)];

// 局部刷新
//一個(gè)section刷新    
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];    
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];    

//一個(gè)cell刷新   
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];   
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone]; 

// 關(guān)于UITableView如何跳轉(zhuǎn)到最后一行或者任意指定行。
其實(shí)現(xiàn)如下:
[self.chatTableView scrollToRowAtIndexPath:
[NSIndexPath indexPathForRow:[self.chatArray count]-1 inSection:0]
  atScrollPosition: UITableViewScrollPositionBottom
  animated:NO];

// 點(diǎn)擊button時(shí)獲取button所在的cell的indexpath
    UIButton *button = sender;
    HeroDermaTableViewCell *cell = (HeroDermaTableViewCell *)[[button superview] superview];
    NSIndexPath *indexPath = [_tableView indexPathForCell:cell];

UIView *backView = [[UIView alloc] initWithFrame:self.bounds];
self.selectedBackgroundView = backView;
self.selectedBackgroundView.backgroundColor = [UIColor clearColor];

將UITableVIew 的屬性 allowsSelectionDuringEdinting 設(shè)置為 TRUE,之后就可在編輯模式下,調(diào)用點(diǎn)擊方法了。

self.tableView.allowsSelectionDuringEditing=YES;
后續(xù)繼續(xù)更新

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

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

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