Search code examples
iphoneiosuitableviewtextlabel

UITableViewCell textLabel width size error Expression is not assignable


I would like to set the frame width of my UITableViewCell label inside tableView:cellForRowAtIndexPath: how ever I am receiving an error.

this is how I am trying to set the cell up.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        [cell.textLabel setLineBreakMode:UILineBreakModeCharacterWrap];
        cell.textLabel.frame.size.width = 200.0; // just as an example.
        [cell.textLabel setMinimumFontSize:FONT_SIZE];
        [cell.textLabel setNumberOfLines:0];
        [cell.textLabel setFont:[UIFont boldSystemFontOfSize:FONT_SIZE]];
        [cell.textLabel setTag:1];

        [[cell contentView] addSubview:cell.textLabel];
    }

but on the line where I try to set textLabel.frame.size.width I get this error

Expression is not assignable


Solution

  • It is self explainable as you can not change width and height property for the UITableViewcell.And more importantly, you can not change the frame of textLabel in UITableViewCell. You should customize the UITableViewCell class.