cocoa-touchuitableviewmultilineios3.0

What's wrong with iOS 3.0 and numberOfLines=0 for UITableViewCell?


ok here's the thing, it's been two days now trying to build a decent tableview cell with subtitles style.

so i overrided the 'tableview:heightforrowatindex:' method. fine i also put the numberoflines for the details to 0.

this works fine in ios4.0

but for ios 3.0 it doesn't it appears that the textlabel and the detailtextlabel are having certain margins at the top which pushes all the cell content downwards to overlap the cell below. This is crazy behaviour. and i couldn't find a way to set the textlabel/detailtextlabel location inside its content view.

Please help. Resizing UITableViewCells in iOS4 versus iOS3 This guy said he's going to implement his own controls. but that's too much work, and it's hard for me. There must be a way that someone already knew to bypass this problem. thanks


Solution

  • actually it seems that the people at apple didn't really make the uitableviewcell as customizable as would a normal developer hope.

    so you would have to customize it by yourself. and sinsce i didn't have time to override UITableViewCell and implement my custom one.

    I have done it hastingly. through

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if( nil == cell ) {     
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"] autorelease];
    
        //contentview
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(1, 5, 11, 9)];
        imageView.image=_headerImage;
    
        UILabel* textLabel=[UILabel new];
            UILabel* detailTextLabel=[UILabel new];
    
    //get and set the size of the labels here 
    
            textLabel.font=_font;
        detailTextLabel.font=_fontD;
        textLabel.numberOfLines=0;
        detailTextLabel.numberOfLines=0;
    
        textLabel.backgroundColor=[UIColor clearColor];
        detailTextLabel.backgroundColor=[UIColor clearColor];
    
        textLabel.tag=202;
        detailTextLabel.tag=203;
        imageView.tag = 204;
    
        [cell.contentView addSubview:imageView];
        [cell.contentView addSubview:textLabel];
        [cell.contentView addSubview:detailTextLabel];
        [textLabel release];
        [detailTextLabel release];
        [imageView release];
    }
    

    of course while implementing

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {   
        if(!_cellTitleSizes)
        {
            _cellTitleSizes= [NSMutableArray new];
            _cellDetailSizes= [NSMutableArray new];
        }
    
        MenuItem *tempItem =[self GetItemFromIndexPath:indexPath];
    
        CGSize size = [ tempItem.title sizeWithFont:_font constrainedToSize:_textSize lineBreakMode:UILineBreakModeWordWrap];
        CGSize size2 = [[MenuListViewController GetDetailsToDisplay:tempItem] sizeWithFont:_fontD constrainedToSize:_textSize lineBreakMode:UILineBreakModeWordWrap];
    
        //the following information will be used to set the title and description labels in the cell.
        [_cellTitleSizes addObject:[NSValue valueWithCGSize:size]];
        [_cellDetailSizes addObject:[NSValue valueWithCGSize:size2]];   
    
        return MAX( (size.height+size2.height)+ 30, 44.0f );
    }
    

    good luck to all of you