2015-05-06 2 views
1

У меня проблема с табличным представлением.Вид таблицы не освежает реальное устройство

Когда я выбрал строку, мой рост ячейки меняется и отображает некоторую информацию. Если я выберу второй раз, он закрывается.

Работает как шарм на симуляторе, но на реальном устройстве первая часть работает нормально, но когда я хочу закрыть его, он выполняет код, но, вероятно, не обновляет tableView, потому что моя информация остается отображаемой.

Другая проблема для реального устройства: мои взгляды не отображаются.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 


     return 4; 

} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if (indexPath.row ==1 &&show == YES) { 
     return 50 + descLabel; 

    }else if (indexPath.row == 2 && show2 == YES){ 

     return caracLabel; 
    } 

    { 
    return 50; 
    } 
} 




    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
     NSString *cellID = @"detailCell"; 
     switch (indexPath.row) { 
      case 0: 
       cellID = @"detailCell1"; 
       break; 

      case 1: 
       cellID = @"detailCell2"; 

       break; 
      case 2: 
       cellID = @"detailCell3"; 
       break; 
      case 3: 
       cellID = @"detailCell4"; 


      default: 
       break; 
     } 

     detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath]; 


     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.label.text = [self.array objectAtIndex:indexPath.row]; 
     cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]]; 

     if (indexPath.row == 1) { 

      if (show == NO) { 
       cell.labelDef.hidden =YES; 


      } 
      } 



     return cell; 


    } 



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
     if (indexPath.row==1) { 
     if (show == NO) { 

      detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell2" forIndexPath:indexPath]; 
      show=YES; 
      cell.label.text = [self.array objectAtIndex:indexPath.row]; 
      cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]]; 
      cell.labelDef.text=[self.desc objectAtIndex:pos]; 
      cell.labelDef.sizeToFit; 
      cell.imageButton.image = [UIImage imageNamed:@"[email protected]"]; 
      cell.labelDef.frame = CGRectMake(10, 50, cell.labelDef.frame.size.width, cell.labelDef.frame.size.height); 
      cell.labelDef.hidden = NO; 
      UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 50, cell.frame.size.width, cell.labelDef.frame.size.height)]; 
      [view setBackgroundColor:[UIColor whiteColor]]; 
      [cell.contentView addSubview:view]; 
      [cell.contentView addSubview:cell.labelDef]; 
      descLabel = cell.labelDef.frame.size.height ; 
    //  [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle]; 
      [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] 
            withRowAnimation:UITableViewRowAnimationNone]; 

      [self.tableView selectRowAtIndexPath:indexPath 
             animated:NO 
            scrollPosition:UITableViewScrollPositionNone]; 

      [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 


     }else{ 

      detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell2" forIndexPath:indexPath]; 
      show= NO; 
      cell.label.text = [self.array objectAtIndex:indexPath.row]; 
      cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]]; 
      cell.imageButton.image = [UIImage imageNamed:@"[email protected]"]; 
      cell.labelDef.hidden = YES; 
    //  [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle]; 
      [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] 
            withRowAnimation:UITableViewRowAnimationNone]; 

      [self.tableView selectRowAtIndexPath:indexPath 
             animated:NO 
            scrollPosition:UITableViewScrollPositionNone]; 

      [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
      } 
     }else if (indexPath.row == 2) { 
      if (show2 == NO) { 
       detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell3"forIndexPath:indexPath]; 
       show2=YES; 
       cell.label.text = [self.array objectAtIndex:indexPath.row]; 
       cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]]; 
       cell.imageButton.image = [UIImage imageNamed:@"[email protected]"]; 
       NSArray *firstWords = [[self.carac objectAtIndex:pos] componentsSeparatedByString:@"\n"]; 
       UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 50, cell.frame.size.width , 100)]; 
       [view1 setBackgroundColor:[UIColor colorWithRed:246/256.0 green:245/256.0 blue:241/256.0 alpha:1]]; 
       [cell.contentView addSubview:view1]; 

       caracLabel = 50; 
       for (int i = 0; i <firstWords.count; i++) { 
         NSArray *array = [[firstWords objectAtIndex:i]componentsSeparatedByString:@"/"]; 

         UILabel *label = [[UILabel alloc]initWithFrame: CGRectMake(10, caracLabel, 90, 20)]; 

         label.text = [array objectAtIndex:0]; 
         label.textColor = [UIColor colorWithRed:150/256.0 green:150/256.0 blue:150/256.0 alpha:1]; 
         label.numberOfLines = 0; 
         [label sizeToFit]; 

         [cell.contentView addSubview:label]; 

         UILabel *label1 = [[UILabel alloc]initWithFrame: CGRectMake(110, caracLabel, 205, 20)]; 

         label1.text = [array objectAtIndex:1]; 
         label1.textColor = [UIColor colorWithRed:150/256.0 green:150/256.0 blue:150/256.0 alpha:1]; 
         label1.numberOfLines = 0; 
         [label1 sizeToFit]; 

         caracLabel = caracLabel + label1.frame.size.height; 
        if (i != firstWords.count - 1) { 

        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, caracLabel, cell.frame.size.width, 1)]; 
        [view setBackgroundColor:[UIColor whiteColor]]; 
        caracLabel =caracLabel+2; 
         [cell.contentView addSubview:view]; 
        } 
         [cell.contentView addSubview:label1]; 

       } 

       UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 1, caracLabel - 50)]; 
       [view setBackgroundColor:[UIColor whiteColor]]; 
       [cell.contentView addSubview:view]; 
       view1.frame = CGRectMake(0, 50, cell.frame.size.width, caracLabel-50); 

    //   [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle]; 
       [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] 
             withRowAnimation:UITableViewRowAnimationNone]; 

       [self.tableView selectRowAtIndexPath:indexPath 
              animated:NO 
             scrollPosition:UITableViewScrollPositionNone]; 

       [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
      } else { 
       detailCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"detailCell3"forIndexPath:indexPath]; 
       show2= NO; 
       cell.label.text = [self.array objectAtIndex:indexPath.row]; 
       cell.image1.image = [UIImage imageNamed:[NSString stringWithFormat:[self.imageArray objectAtIndex:indexPath.row]]]; 
       cell.imageButton.image = [UIImage imageNamed:@"[email protected]"]; 

    //   [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationMiddle]; 
       [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] 
             withRowAnimation:UITableViewRowAnimationNone]; 

       [self.tableView selectRowAtIndexPath:indexPath 
              animated:NO 
             scrollPosition:UITableViewScrollPositionNone]; 

       [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 
      } 
     }else 
     if (indexPath.row == 3){ 
      NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[self.wiki objectAtIndex:pos]]]; 
      UIWebView *video = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - +50)]; 
      [video loadRequest:request]; 
      video.delegate=self; 
      showWeb = YES; 
      UIActivityIndicatorView *actInd=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
      actInd.color=[UIColor blackColor]; 
      [actInd setCenter:self.view.center]; 
      self.activityIndicator=actInd; 
      [self.view addSubview:video]; 

      [video addSubview:self.activityIndicator]; 
     } 

    } 

Это как смотрит/работу на тренажере: замкнутых closed

Description- description

caracteristics- caracteristics

И это, как работает для реального устройства: Описания поставщика- enter image description here

caracteristics- enter image description here

замкнутому enter image description here и enter image description here

Я не знаю, если это проблема, но строка меняется цвет после того, как я нажимаю первый раз в реальном устройстве. Зачем? Есть идеи?

+0

Я предполагаю, что это происходит при прокрутке? – iphonic

+0

Нет. Моя строка просто не закрывается .. :( –

+0

Не включайте функцию прокрутки и попробуйте ее –

ответ

0

Если все работает хорошо в симуляторе, но не на устройстве, то проверьте значения «dequeueReusableCellWithIdentifier»/«CellID», потому что симулятор не чувствителен к регистру, но устройство чувствительно к регистру.

Возможно, он не узнает ваш идентификатор ячейки, так что это произойдет, я не уверен в этом, но просто проверяю один раз.

Смежные вопросы