2013-10-19 18 views
5

Tôi có chế độ xem bảng và tôi đặt tất cả chiều cao ô lẻ = 0, Trong ô lẻ tôi có một số nhãn. Khi nó hiển thị dạng xem bảng, nhãn trong ô lẻ xuất hiện trong ô chẵn. Có cách nào để làm cho nhãn biến mất không? Vấn đề này xảy ra trong ios 6 p/s: trong ios 7: nó hoạt động đúng. tôi đã có phương thức: [tableView beginUpdates]; [tableView endUpdates];heightForRowAtIndexPath = 0 nhưng nó vẫn hiển thị nhãn trong hàng của nó

Cảm ơn.

- (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

Điều gì sẽ xảy ra nếu bạn đặt cắt bớt các bản xem trước thành có cho contentView của ô? – Zen

+0

cách đặt? xin lỗi vì tôi là newbie – tommy

+1

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

Trả lời

20

[cell setClipsToBounds: YES]; trong cellForRowAtIndexPath

làm việc cho tôi. Hy vọng bạn tìm thấy giải pháp của bạn.

+1

tiết kiệm cuộc sống của tôi. :) – yuhua

+0

Cùng với me.Cheers – Allamaprabhu

+0

Giải pháp hay, Thx! –

3

Sau khi đọc câu trả lời của người dùng2799736 Tôi đã thay đổi Clip Subviews thành CÓ trong tệp .xib. Làm việc cho tôi.

+0

Giải pháp tuyệt vời, Thx! –

Các vấn đề liên quan