2014-09-22 7 views
7

tamamı tableViewspropertySeparatorInset saygı değildir. Hepsi iOS 7 üzerinde çalışıyordu, ama artık değil.Özel UITableView ayırıcısı, iOS 8'de storyboard'larla çalışmaz. <code>Custom</code> - - <code>storyBoard</code> üzerinde <code>left = 0</code> benim app

Ben uygulamak yöntemlerinin altındaki iki: Bu doğru çalıştığından

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // iOS 7 
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { 
     [cell setSeparatorInset:UIEdgeInsetsZero]; 
    } 
    // iOS 8 
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { 
     [cell setLayoutMargins:UIEdgeInsetsZero]; 
    } 
} 

-(void)viewDidLayoutSubviews 
{ 
    // iOS 7 
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { 
     [self.tableView setSeparatorInset:UIEdgeInsetsZero]; 
    } 
    // iOS 8 
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { 
     [self.tableView setLayoutMargins:UIEdgeInsetsZero]; 
    } 
} 

, ben sadece daha basit şekilde storyboard bu ayarı devam edemez neden anlamıyorum.

Herhangi bir düşünce?

cevap

5

Bu kod size yardımcı olabilir. , Yöntemin aşağıdaki gibi hücreyi yapılandırın:

if ([self.tableView respondsToSelector:@selector(layoutMargins)]) { 
    self.tableView.layoutMargins = UIEdgeInsetsZero; 
} 

Sonra cellForRowAtIndexPath içinde şu şekildedir:

Önce masa görünümü yapılandırmak: hem layoutMargins ve separatorInset, iOS8 için 7,8 hem iOS sürümleri destekleyen Dahil :

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 
    if ([self respondsToSelector:@selector(setLayoutMargins:)]) { 
    cell.layoutMargins = UIEdgeInsetsZero; 
    } 
#endif 
:

sürümü için
if ([cell respondsToSelector:@selector(layoutMargins)]) { 
    cell.layoutMargins = UIEdgeInsetsZero; 
} 

aşağıdaki şeyler kullanabilirsiniz kontrol

+0

Peki, teşekkürler. ama kod açısından, kodum iyi çalışıyor. Ayırıcı girintisini herhangi bir kod olmaksızın film şeridinde ayarlayabilmek istedim. Ancak, iOS 8'de çalışmıyor gibi görünüyor. – Jorge

+0

Ben de bu sorunu yaşıyorum. Paraya çevirebileceğim bir radar mı yaptın? –

1
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
    // Remove separator inset 
    if cell.respondsToSelector("setSeparatorInset:") { 
     cell.separatorInset = UIEdgeInsetsZero 
    } 

    // Prevent the cell from inheriting the Table View's margin settings 
    if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") { 
     if #available(iOS 8.0, *) { 
      cell.preservesSuperviewLayoutMargins = false 
     } 
    } 

    // Explictly set your cell's layout margins 
    if cell.respondsToSelector("setLayoutMargins:") { 
     if #available(iOS 8.0, *) { 
      cell.layoutMargins = UIEdgeInsetsZero 
     } 
    } 
} 
0

kolay:

cell.separatorInset = UIEdgeInsetsMake (0.0, CGRectGetWidth (tableView.frame)/2, 0.0, CGRectGetWidth (tableView.frame)/2);

İlgili konular