2014-09-22 10 views
7

Tutte le tableViews della mia app non rispettano lo propertySeparatorInset - Custom - left = 0 su storyBoard. Funzionava tutto bene su iOS 7, ma non più.Il separatore di UITableView personalizzato non funziona su iOS 8 con storyboard.

Quando a implementare i due metodi di seguito:

-(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]; 
    } 
} 

Funziona correttamente, io proprio non capisco perché non riesco a mantenere l'impostazione su questo storyboard che è molto più semplice.

Qualche idea?

risposta

5

Questo codice può essere d'aiuto. includono sia layoutMargins e separatorInset, per sostenere entrambe le versioni iOS 7,8 Per iOS 8:

Prima configurare la visualizzazione tabella come segue:

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

Poi, nel tuo cellForRowAtIndexPath: metodo, configurare il cellulare come segue :

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

Per la versione di controllo è possibile utilizzare seguenti cose:

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

Bene, grazie. ma in termini di codice, il mio codice funziona bene. Volevo solo essere in grado di impostare il rientro del separatore nello storyboard, senza alcun codice. Ma non sembra funzionare su iOS 8. – Jorge

+0

Anche io ho questo problema. Hai archiviato un radar che posso ingannare? –

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

Facile:

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

Problemi correlati