之前一直以為tableView的cell 下面的一條黑色的細(xì)線仆嗦,會(huì)出現(xiàn)一些空白是因?yàn)閄code的模擬器抽風(fēng)造成的昧谊,而今年我才發(fā)現(xiàn)我錯(cuò)了靡菇,哈哈哈錯(cuò)的很離譜,原來那是iOS7.0以后cell上邊的那條黑色的線的左邊會(huì)出現(xiàn)15像素的空白至壤,所以,就轉(zhuǎn)載了這篇文章枢纠,與君共勉像街。
轉(zhuǎn):
在ios7中,UITableViewCell左側(cè)會(huì)有默認(rèn)15像素的空白。這時(shí)候宅广,設(shè)置setSeparatorInset:UIEdgeInsetsZero 能將空白去掉葫掉。
但是在ios8中,設(shè)置setSeparatorInset:UIEdgeInsetsZero 已經(jīng)不起作用了跟狱。下面是解決辦法
首先在viewDidLoad方法加入以下代碼:
if([self.tableViewrespondsToSelector:@selector(setSeparatorInset:)]) {[self.tableView setSeparatorInset:UIEdgeInsetsZero];}if([self.tableViewrespondsToSelector:@selector(setLayoutMargins:)]) {[self.tableView setLayoutMargins:UIEdgeInsetsZero];}
然后在UITableView的代理方法中加入以下代碼
-(void)tableView:(UITableView*)tableViewwillDisplayCell:(UITableViewCell*)cellforRowAtIndexPath:(NSIndexPath*)indexPath{if([cellrespondsToSelector:@selector(setSeparatorInset:)]) {[cell setSeparatorInset:UIEdgeInsetsZero];}if([cellrespondsToSelector:@selector(setLayoutMargins:)]) {[cell setLayoutMargins:UIEdgeInsetsZero];}}
這樣俭厚,空白就沒有了
文章轉(zhuǎn)載自(http://blog.csdn.net/yesjava/article/details/41039961)