2016-06-24 16 views
0

Ich verwende eine Tabellenansicht mit AutoLayet Ecken auf (0,0,0,0) gesetzt. Ich hatte eine benutzerdefinierte Zelle auf dem Tisch view.Mein Problem ist die scrollToRowAtIndexPath funktioniert nicht gut.Meine cellForRowAtIndexPath Methoden sieht so ausscrollToRowAtIndexPath funktioniert nicht ordnungsgemäß?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    RTableViewCell *cell = (RTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell==nil) 
    { 
     for (UIView *currentView in tableView.subviews) { 
      if ([currentView isKindOfClass:[UIScrollView class]]) { 
       ((UIScrollView *)currentView).delaysContentTouches = NO; 
       break; 
      } 
     } 
     UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame]; 
     myBackView.backgroundColor =[UIColor colorWithRed:216/255.0 green:231/255.0 blue:244/255.0 alpha:1.0]; 
     cell.selectedBackgroundView = myBackView; 

    return cell;  
} 

Ich hatte dynamische Anzahl der Abschnitte und dynamische Anzahl der Zeilen in diesem. und in meinem viewDidAppear Ich mag dieses

dispatch_async(dispatch_get_main_queue(), ^{ 
    //int indexValue = (int)[sections indexOfObject:string]; 
    [rtable reloaddata]; 
     NSIndexPath *rowIndexPath = [NSIndexPath indexPathForRow:0 inSection:6]; 
    [self.rtable scrollToRowAtIndexPath:rowIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; 
}); 

jemand nenne weiß, wo ich falsch gehe?

+0

Was ist das erwartete Ergebnis und was passiert stattdessen? – Code

+0

Ich wollte die Tabellenansicht in der 6. Zeile in der 0. Zeile, aber es ist nur Scrollen bis zum 3. Abschnitt. – hacker

+0

Sind Sie sicher, dass genügend Zeilen vorhanden sind, um in positionTop zu Abschnitt 6 scrollen zu können? Möglicherweise müssen Sie etwas unteres Leerzeichen über contentInset hinzufügen – danh

Antwort

0

Try Code unten in viewWillAppear oder viewDidLayoutSubviews:

[rtable reloaddata]; 

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 

     NSIndexPath *rowIndexPath = [NSIndexPath indexPathForRow:0 inSection:6]; 
     [self.rtable scrollToRowAtIndexPath:rowIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES]; 

    }); 
Verwandte Themen