2012-08-30 43 views
0

我想在tableView:cellForRowAtIndexPath:中設置我的UITableViewCell標籤的幀寬度,我怎麼會收到一個錯誤。UITableViewCell textLabel寬度大小錯誤表達式不可分配

這是我如何設置單元格。

- (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]; 
    } 

,但是,在這裏我嘗試設置textLabel.frame.size.width我得到這個錯誤

表達該行不分配

回答

1

這是自我解釋,但是你不能改變widthheight屬性爲UITableViewcell。更重要的是,您不能在UITableViewCell中更改textLabel的框架。你應該自定義UITableViewCell類。

1

你不能這樣做,如果你想這樣做,那麼它不會給出任何錯誤,但它不會影響你的代碼.....所以,只需簡單的標籤,然後設置框架,然後將其添加到你的手機。

[cell addSubview:YourLbl];