2016-11-07 2 views
0

Ich habe ein seltsames Verhalten mein TableView Ich mache Drop-Down-Abschnitt auf meinem TableView. Es ist wie folgt aussehen:UITableView Zeilenreihenfolge

enter image description here

aber wenn ich meine Abschnitt Reihen, um wie dies ather wieder öffnen:

enter image description here

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     NSLog(@"CURRENT ROW = %ld", (long)indexPath.row); 
     UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(90, 20, cell.frame.size.width - 90, 20)]; 
     titleLable.text = [NSString stringWithFormat:@"урок %ld", (long)indexPath.row]; 
     [cell addSubview:titleLable]; 
     UILabel *percentLable = [[UILabel alloc] initWithFrame:CGRectMake(cell.frame.size.width - 40, 20, 50, 20)]; 
     LessonModel *lesson = [self.lessonsArray objectAtIndex:indexPath.section]; 
     NSArray *childrenArrey = [[NSArray alloc] initWithArray:(NSArray *) lesson.childrenArray];; 
     percentLable.text =[NSString stringWithFormat:@"%@ %%", [childrenArrey[indexPath.row] valueForKey:@"percent"]]; 
     [cell addSubview:percentLable]; 
    } 
} 
return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
LessonModel *lesson = [self.lessonsArray objectAtIndex:indexPath.section]; 
NSArray *childrenArrey = [[NSArray alloc] initWithArray:(NSArray *) lesson.childrenArray]; 
NSString *uid = [childrenArrey[indexPath.row] valueForKey:@"id"]; 
[self makeLessonWithId:uid]; 
} 

- (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer{ 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:gestureRecognizer.view.tag]; 
if (indexPath.row == 0) { 
    BOOL collapsed = [[self.arrayForBool objectAtIndex:indexPath.section] boolValue]; 
    collapsed  = !collapsed; 
    [self.arrayForBool replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithBool:collapsed]]; 
    [self updateLabelFrame:gestureRecognizer.view.tag]; 

    NSRange range = NSMakeRange(indexPath.section, 1); 
    NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range]; 
    [self.tableView reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationFade]; 
} 
} 
+0

Warum müssen Sie den Abschnitt neu laden? – Sofeda

+0

für Update-Abschnitt und zeigen Sie alle Zeilen –

Antwort

0

Versuchen von Werten in anderen Teil stülpen zu:

if (cell == nil){ 
      //your code as it is 
    } 
    else{ 
      titleLable.text = [NSString stringWithFormat:@"урок %ld", (long)indexPath.row]; 
      NSArray *childrenArrey = [[NSArray alloc] initWithArray:(NSArray *) lesson.childrenArray];; 
      percentLable.text =[NSString stringWithFormat:@"%@ %%", [childrenArrey[indexPath.row] valueForKey:@"percent"]]; 
    } 
+0

es ist nicht meine Probleme zu lösen –