简体   繁体   中英

UILabel on UITableViewCell does not appear correctly

I have an interface configured using constraints in interface builder. It is set up as shown: http://imgur.com/a/xqa7D .

When the cell is rendered, the right hand label does not appear (but a space for it remains): http://imgur.com/xwBSSMD .

The cell in question is a custom UITableViewCell subclass:

#import <UIKit/UIKit.h>

@interface ProgressCell : UITableViewCell

@property (weak, nonatomic) IBOutlet UILabel *textLabel;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *detailTextLabel;

@end

There is no further logic on the class.

The table view cell is instantiated from the identifier that I have set on the storyboard:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ProgressCell";
    ProgressCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
                                                         forIndexPath:indexPath];

    Object *room = [self.rooms objectAtIndex:indexPath.row];
    cell.textLabel.text = room.name;
    cell.progressView.progress = 1.0f - ((float)room.avail)/room.total;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%d/%d", room.avail, room.total];

    return cell;
}

If I set a breakpoint at the end of the function and do po [[cell detailTextLabel] text] , the text is set correctly. The label is not hidden.

I am completely at a loss as to the possible cause. What could be triggering this behaviour?

Other things I've tried:

  • renaming the property to something other than detailTextLabel (in case of a possible clash) does not work
  • if I add a third label, with default text, that shows correctly
  • if I add a third label and connect that outlet in IB to the one that does not appear, then the default text for the problem label appears, but the third label is hidden

EDIT:

If I log the ultimate position of the frame in question, it sits at {{0, 44}, {0, 0}} .

Things you can try to find out whats happening:

  • Put a red background on the label.

  • Do an NSLog with the label's frame and your cell's contentView frame.

  • Put a hardcoded text on it. cell.detailTextLabel.text = @"Hi";

问题可能是情节提要自动布局的约束。请检查标签约束,以便在表格视图中调整单元格大小时可见

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM