2016-11-07 55 views
0

我有一个奇怪的行为我的tableView 我让我的tableView下拉节。它看起来像:UITableView行排序

enter image description here

但如果我重新开始我的部分行的次序是粥这样的:

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

为什么您需要重新加载该部分? – Sofeda

+0

为更新部分并显示所有行 –

回答

0

尝试把值中的其他部分也:

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

它不能解决我的问题 –