Cannot update UI object's frame in UITableViewCell

后端 未结 6 2029
眼角桃花
眼角桃花 2021-01-19 02:18

I have a subclassed UITableViewCell.

I need to dynamically change the frame of a UILabel.

Here\'s what I\'ve done:

- (UITableViewCell *)table         


        
6条回答
  •  日久生厌
    2021-01-19 02:51

    May be this relates to fact of reusing cell. Try this

      - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            static NSString *CellIdentifier = @"messageCell";
            MessageCell *cell = (MessageCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
        if(cell == nil)
           { 
            cell = [[[MessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autorelease];
            }
            cell.Content.Text = @"Content!";
            [cell.Content setFrame:CGRectMake(0, 0, 10, 10)];
            return cell;
        }
    

提交回复
热议问题