2015-07-21 78 views
1

使用此代碼展開表格視圖單元格,但它不適用於我。我知道這段代碼有一些錯誤幫助我找出答案。如何展開我的表格視圖單元格?

![selectindex = -1; 

    // Do any additional setup after loading the view. 

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

{ 

    return 1; 
} 
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return \[Arr_lbl count\]; 
} 
#pragma mark table cell creating and loading the data 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    AntzclubCell *cell=\[tableView dequeueReusableCellWithIdentifier:@"Antz"\]; 
    cell.img_antzClub.image=\[UIImage imageNamed:\[Arr_img objectAtIndex:indexPath.row\]\]; 
    cell.lbl_antzClub.text=\[Arr_lbl objectAtIndex:indexPath.row\]; 
    cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton; 
    cell.backgroundColor=\[UIColor blackColor\]; 
    return cell; 
} 
#pragma mark expanding height 
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(selectindex==indexPath.row){ 
     return 400; 
    } 
    else{ 
     return 132; 
    } 

} 
#pragma mark user selecting option 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row==selectindex) { 

     selectindex=-1; 
     \[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\]; 
     return; 
    } 
     if(selectindex !=-1) 
     { 
      NSIndexPath *prepath=\[NSIndexPath indexPathForRow:selectindex inSection:0\]; 
      selectindex=indexPath.row; 
      \[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:prepath\] withRowAnimation:UITableViewRowAnimationLeft\]; 
     } 
     selectindex=indexPath.row; 
     \[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\]; 
    }] 

enter image description here 這個形象是我的輸出,而我單擊單元格與其他數據未擴大合併。

+0

每一個細胞都具有不同的高度? –

+0

是不同的高度,但現在我爲每個單元實現了相同的高度。 –

+0

所以你可以使用外部API類,這是幫助你。你可以在你的應用程序中使用外部api類,或者在應用程序中複製外部api代碼。 –

回答

0

根據您想要支持的答案可能有所不同了iOS版本,但似乎你沒有實現heightForRowAtIndexPath:

+1

我實現了索引路徑上行的估計高度是我的代碼中的任何錯誤請提及。 –

+0

你需要實現'heightForRowAtIndexPath:'你的代碼是錯誤的,因爲你沒有實現它,你沒有表明你正在使用自定義的單元格。 – sylvanaar

+0

好吧,我會嘗試根據您的建議.. –

相關問題