Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

heightForRowAtIndexPath =0 but it still display the label in its row

I have a table view and I set all of the odd cell height = 0, In odd cell I had some labels. When it show up the table view, the label in odd cell appear in the even cell. Is there any way to make the label vanish? This problem happened in ios 6 p/s: in ios 7: it work right. i already had the method : [tableView beginUpdates]; [tableView endUpdates];

Thanks.

- (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;
    }
}
like image 432
tommy Avatar asked Oct 19 '13 05:10

tommy


2 Answers

[cell setClipsToBounds:YES]; in cellForRowAtIndexPath

worked for me. Hope you found your solution.

like image 145
user2799736 Avatar answered Nov 13 '22 04:11

user2799736


After reading user2799736 answer I changed Clip Subviews to YES in .xib file. Worked for me.

like image 4
imba_man Avatar answered Nov 13 '22 03:11

imba_man