chdtyzhy

iOS 8下使用xib/storybord AutoLayout导致的分割线问题

/***

  iOS8 分割线问题 在xib/storyboard下面解决方案

  http://qiita.com/yimajo/items/10f16629200f1beb7852

  http://www.cocoachina.com/ios/20141026/10045.html

  http://www.2cto.com/kf/201411/349631.html

  http://dev.classmethod.jp/smartphone/iphone/ios-8-uitableview-layoutmargins/

  http://demo.netfoucs.com/growinggiant/article/details/42002871

 */

 

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
     [self.view setLayoutMargins:UIEdgeInsetsZero];
    
//    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
//        
//        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
//        
//    }
//    
//    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
//        
//        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];
//        
//    }
//    [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
 
}
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
//       [self.tableView setLayoutMargins:UIEdgeInsetsZero];
        [self.view setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 100;

}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *ID = @"TableViewCell";
   UITableViewCell*cell =  [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell==nil) {
        UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:ID];
        return [[nib instantiateWithOwner:nil options:nil]lastObject];

    }
//    cell.preservesSuperviewLayoutMargins = NO;
//    if ([cell respondsToSelector:@selector(setSeparatorInset:)])   {
//        cell.separatorInset = UIEdgeInsetsZero;
//    }
//    
//    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
//        cell.preservesSuperviewLayoutMargins = false;
//    }
//    
//    if( [cell respondsToSelector:@selector(setLayoutMargins:)]) {
//        cell.layoutMargins = UIEdgeInsetsZero;
//          [self.view setLayoutMargins:UIEdgeInsetsZero];
//    }

    return cell;
    
}
//然后在UITableView的代理方法中加入以下代码
//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
//
//{
//    
//    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
//        
//        [cell setSeparatorInset:UIEdgeInsetsZero];
//        
//    }
//    
//    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
//        
//        [cell setLayoutMargins:UIEdgeInsetsZero];
//        
//    }
//    
//}

 

posted on 2015-04-29 18:44  勇@  阅读(889)  评论(0编辑  收藏  举报

导航