2013-10-09 117 views
0

我想刪除iPhone應用程序中的tableview單元格,它們也是空的和隱藏的。但這些cells.we採取的空間已經使用這個代碼我想要刪除tableview中的空單元格和隱藏的單元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell * cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; 

    if([cell isKindOfClass:[IASKPSTextFieldSpecifierViewCell class]]) 
    { 
     UITextField *field = ((IASKPSTextFieldSpecifierViewCell*)cell).textField; 
     [field setTextColor:LINPHONE_MAIN_COLOR]; 

    } 
    cell.detailTextLabel.textColor = [UIColor blackColor]; 

    // Background View 
    UACellBackgroundView *selectedBackgroundView = [[[UACellBackgroundView alloc] initWithFrame:CGRectZero] autorelease]; 
    cell.selectedBackgroundView = selectedBackgroundView; 
     if (indexPath.section==1) 
    { 
     if (indexPath.row== 1) 
     { 
      cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; 
      return cell; 
     } 


    } 
    if(indexPath.section==0) 
    { 
     //NSLog(@"value is--%@",); 
     if ([cell.textLabel.text isEqualToString:@"Opus 48kHz"]) 
     { 
      [email protected]"G.711U-law"; 
     } 
     if ([cell.textLabel.text isEqualToString:@"Silk 24Khz"]) 
     { 
      [email protected]"G.711A-law"; 
     } 
     if ([cell.textLabel.text isEqualToString:@"Silk 16Khz"]) 
     { 
      [email protected]"GSM"; 
     } 
     if ([cell.textLabel.text isEqualToString:@"AAC-ELD 22kHz"]) 
     { 
      [email protected]"iLBC30"; 
     } 


     if (indexPath.row==6) 
     { 

      cell.hidden=YES; 
      // cell=nil; 
     } 
     if (indexPath.row==7) 
     { 

      cell.hidden=YES; 
      //cell=nil; 
     } 
     if (indexPath.row==8) 
     { 

      cell.hidden=YES; 
      //cell=nil; 
     } 
     if (indexPath.row==9) 
     { 
      cell.hidden=YES; 
      //cell=nil; 
     } 

     if (indexPath.row==10) 
     { 
      cell.hidden=YES; 
      //cell=nil; 
     } 
     if (indexPath.row==11) 
     { 
      cell.hidden=YES; 
      //cell=nil; 
     } 
    } 
    else 
    { 
     cell.hidden=YES; 
      return cell; 
    } 

    self.tableView.separatorColor=[UIColor blackColor]; 
    return cell; 

} 
+2

我承認你。 –

+2

哈哈哈..我也承認你:) – Rajneesh071

+0

你有沒有想過在storyboard或xib中創建靜態tableview? – Abizern

回答

0

只需從tableArray刪除數據,然後重新加載table,這將刪除該單元格。

0

您的數據源必須反映您需要在表格視圖中顯示的內容,在cellForRowAtIndexPath中您必須配置(以及alloc/init,如果需要)單元格,當不需要單元格時它將自動由表視圖釋放。

P.S.你發佈的代碼是OMG ... O.O