2013-10-19 72 views
5

我有一個表格視圖,我設置了所有奇數單元格高度= 0,在奇數單元格中我有一些標籤。當它顯示錶格視圖時,奇數單元格中的標籤出現在偶數單元格中。有沒有辦法讓標籤消失?這個問題發生在ios 6 p/s: 在ios 7中:它工作正常。 我已經有了方法:[tableView beginUpdates]; [tableView endUpdates];heightForRowAtIndexPath = 0但它仍然在其行中顯示標籤

謝謝。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    // show odd row 
    if (selectedRow == indexPath.row) return 78; 

    // hide odd row and show even row 
    if (indexPath.row %2 ==0){ 
     return 88;} 
    else{ 
     return 0;} 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 


    if (indexPath.row%2 == 0){ 


     //user click on even row -> display the next row 
     selectedRow = indexPath.row+1; 

     [tableView beginUpdates]; 

     [tableView endUpdates]; 

    } 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    int index = indexPath.row/2; 

    if (indexPath.row %2 ==0){ 

     static NSString *CellIdentifier = @"PhraseViewCell"; 

     PhraseCellVietnamese *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

     NSString *phrase = [[phrases objectAtIndex:index] objectForKey:@"vietnamese"]; 

     NSNumber *checkFavorite = [[phrases objectAtIndex:index] objectForKey:@"favorite"]; 

     NSNumber *phraseId =[[phrases objectAtIndex:index] objectForKey:@"_id"]; 

     [cell SetInfo:phrase :checkFavorite.intValue :phraseId.intValue]; 

     return cell; 

    } 
    else{ 

     static NSString *CellIdentifier = @"PinyinViewCell"; 

     PinYinViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

     NSString *pinyin = [[phrases objectAtIndex:index] objectForKey:@"pinyin"]; 

     NSString *chinese = [[phrases objectAtIndex:index] objectForKey:@"chinese"]; 

     NSString *voice = [[phrases objectAtIndex:index] objectForKey:@"voice"]; 

     [cell setInfo:pinyin :chinese :voice]; 

     return cell; 
    } 
} 
+0

如果將單元格的contentView的剪貼子視圖設置爲yes,該怎麼辦? – Zen

+0

如何設置?對不起,因爲我是新手 – tommy

+1

'[cell.contentView setClipsToBounds:YES];' – Zen

回答

20

[cell setClipsToBounds:YES];在cellForRowAtIndexPath

爲我工作。希望你找到你的解決方案。

+1

拯救我的生命。 :) – yuhua

+0

同我一起。乾杯 – Allamaprabhu

+0

不錯的解決方案,Thx! –

3

After reading user2799736 answer I changed Clip Subviews to .xib file。 爲我工作。

+0

不錯的解決方案,Thx! –

相關問題