2015-06-20 5 views
1

Я использую UITableView для отображения различных данных на экране. Я использую UITableViewCell, созданный кодом в .m файле. Они представляют собой 9 различных типов ячеек с 0 различными идентификаторами и высотами для ячейки. когда одна и та же ячейка с двумя разными высотами в таблице начинает перекрывать друг друга.UiTbleview Cell Overlapping при прокрутке больше времени

Здесь я помещаю код для высоты ячейки метода.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row ==0) 
    { 
     return 120.0; 
    } 
    else{ 
     //For Action User follow 
     if(condition) 
     { 
      //Checking if the Follow is shared or not 
      if() 
      { 
       //Checking the number of Counts 
       if() 
       { 
        if() 
        { 
         if() 
         { 
          return 340.0+(arTemp1.count*50.0); 
         } 
         else 
         { 
          return 157.0+(arTemp1.count*50.0); 
         } 
        } 
        else 
        { 
         if() 
         { 
          return 340.0+200; 
         } 
         else 
         { 
          return 157.0+200; 
         } 
        } 
       } 
       else 
       { 
        if() 
        { 
         return 340.0f; 
        } 
        else{ 
         return 157.0f; 
        } 
       } 
      } 
      else 
      { 
       if(arTemp1.count>0) 
       { 
        if(arTemp1.count <4) 
        { 
         if() 
         { 
          height=height+150; 
         } 
         return height+(arTemp1.count*50.0); 
        } 
        else 
        { 
         if() 
         { 
          height= height; 
         } 
         return height; 
        } 
       } 
       else 
       { 
        if() 
        { 
         height= height+40; 
        } 
        return height; 
       } 
      } 
     } 
     else if() 
     { 
      if(arTemp1.count>0) 
      { 
       if(arTemp1.count <4) 
       { 
        return 160.0+(arTemp1.count*50.0); 
       } 
       else 
       { 
        return 160.0+200; 
       } 
      } 
      else 
      { 
       return 150.0f; 
      } 
     } 
     //For Action Add New Reciepe 
     else if() 
     { 
      if(arTemp1.count>0) 
      { 
       if(arTemp1.count <4) 
       { 
        return 420.0+(arTemp1.count*50.0); 
       } 
       else 
       { 
        return 420.0+200; 
       } 
      } 
      else 
      { 
       return 400.0f; 
      } 
     } 
     else if() 
     { 
      if(arTemp1.count>0) 
      { 
       if(arTemp1.count <4) 
       { 
        return 350.0+(arTemp1.count*50.0); 
       } 
       else 
       { 
        return 350.0+200; 
       } 
      } 
      else 
      { 
       return 350.0f; 
      } 
     } 
     //For Action Added new page 
     else if() 
     { 
      if(arTemp1.count>0) 
      { 
       if(arTemp1.count <4) 
       { 
        return 350.0+(arTemp1.count*50.0); 
       } 
       else 
       { 
        return 350.0+200; 
       } 
      } 
      else 
      { 
       return 350.0f; 
      } 
     } 
     else if() 
     { 
      if(arTemp1.count>0) 
      { 
       if(arTemp1.count <4) 
       { 
        return 170.0+(arTemp1.count*50.0); 
       } 
       else 
       { 
        return 150.0+200; 
       } 
      } 
      else 
      { 
       return 150.0f; 
      } 
     } 
     //For Action Add Photo 
     else if() 
     { 
      if(arTemp1.count>0) 
      { 
       if(arTemp1.count <4) 
       { 
        return 350.0+(arTemp1.count*50.0); 
       } 
       else 
       { 
        return 350.0+200; 
       } 
      } 
      else 
      { 
       return 350.0f; 
      } 
     } 
    } 
    return 0.0f; 
} 

Cell для кода строки

 NSString *CellIdentifier = @"a"; 

     UITableViewCell *a = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     if (a == nil) 
     { 
      //Follow Cell Initializing 
      a = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
      a.selectionStyle = UITableViewCellSelectionStyleNone; 
      a.tag=a; 

      //Create Cell Method 
      [self aCreateCell:a atIndexPath:indexPath]; 
     } 

     // Set Cell Method 
     [self aSetCell:a atIndexPath:indexPath]; 
     [a setClipsToBounds:YES]; 
     return a; 
+0

показать код для cellforrowatindexpath –

ответ

1

попробовать это

Сначала вы зарегистрировать свой класс клеток с Tableview

- (void)viewDidLoad{ 

/*IF You are using class */ 

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellIdentifire"]; 

/* if you are using nib */ 

// LOAD UP THE NIB FILE FOR THE CELL 
UINib *nib = [UINib nibWithNibName:@"CustomNibCell" bundle:nil]; 

// REGISTER THE NIB FOR THE CELL WITH THE TABLE 
[self.tableView registerNib:nib forCellWithReuseIdentifier:@"cellIdentifire"]; 

} 

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

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifire" forIndexPath:indexPath]; 

     /* 

     Write code 


     cell.title= @"hello"; 
     */ 
     return cell; 

    } 
+0

Это крах приложения провал утверждение - [UITableView dequeueReusableCellWithIdentifier: forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116 –

+0

@GauravParmar на каком устройстве и что проверяет версия iOS? – Aanabidden

+0

Я проверяю ios 8.2 и в iphone 5s –

0

Вы создаете вы клеточными и мечения только тогда, когда его nil, iOS повторно использует ячейку, поэтому вам нужно каждый раз настраивать свою ячейку.

NSString *CellIdentifier = @"a"; 

    UITableViewCell *a = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (a == nil) 
    { 
     //Follow Cell Initializing 
     a = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     a.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    a.tag=a; 

    //Create Cell Method 
    [self aCreateCell:a atIndexPath:indexPath]; 

    // Set Cell Method 
    [self aSetCell:a atIndexPath:indexPath]; 
    [a setClipsToBounds:YES]; 
    return a; 
+0

, но я не использую тег нигде в представлении. его просто моя практика пометить все элементы управления так. удалить его также не сделал никаких изменений. –

+0

@GauravParmar не тег, вам нужно переместить свой метод создания из нулевого уровня, так как вы его не используете, вы также можете его удалить. – Aanabidden

+0

Можете ли вы объяснить мне, почему мне нужно удалить метод снаружи. поскольку этот метод используется для добавления контроля для просмотра. 1.createcell метод используется для добавления контроля на ячейку 2.setcell метод используется для установки значения в ячейку –