UITableView移除某一行cell的分割线
生活随笔
收集整理的這篇文章主要介紹了
UITableView移除某一行cell的分割线
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
以前一直以為不能單獨去掉cell的一行分割線,所以處理特殊的UI時,甚至用嵌套UITableView,最終導致處理邏輯變得相對復雜了;
直到今天才恍然大悟,尼瑪還可以這樣去"移除"某一行的分割線,心理各種吐血.....
不多說,見代碼:
?
// // ViewController.m // CKTableView // // Created by CK on 16/5/13. // Copyright ? 2016年 CK. All rights reserved. //#import "ViewController.h"@interface ViewController ()<UITableViewDataSource> {UITableView *myTableView; } @end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];myTableView = [UITableView new];myTableView.backgroundColor = [UIColor whiteColor];myTableView.frame = self.view.bounds;myTableView.dataSource = self;[self.view addSubview:myTableView];if ([myTableView respondsToSelector:@selector(setSeparatorInset:)]) {[myTableView setSeparatorInset:UIEdgeInsetsZero];}if ([myTableView respondsToSelector:@selector(setLayoutMargins:)]) {[myTableView setLayoutMargins:UIEdgeInsetsZero];}}#pragma mark - - UITableViewDataSource- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 10; }- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *identity = @"displaycell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identity];if (!cell) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity];}if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {[cell setSeparatorInset:UIEdgeInsetsZero];}if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {[cell setLayoutMargins:UIEdgeInsetsZero];}//指定隱藏第二行分割線if (indexPath.row==2) {[cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, MAXFLOAT)];}cell.textLabel.text = [NSString stringWithFormat:@"測試 %lu",indexPath.row];return cell; }@end?
轉載于:https://my.oschina.net/sfandy/blog/674757
總結
以上是生活随笔為你收集整理的UITableView移除某一行cell的分割线的全部內容,希望文章能夠幫你解決所遇到的問題。