0

I have a .xib with 2-3 NSTextFields displayed in it (as shown below). I would like to resize one of these NSTextFields so it best fits the content it is displaying. My problem is that I cannot change the size of the Text Field in the viewForTableColumn at all.

enter image description here

I have successfully set my heightOfRow. That is working nicely.

I have turned off AutoLayout for the field as it wasn't quite working properly for me.

Now in tableView viewForTableColumn I have the following code:

func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView?
{
    let cell = tableView.makeViewWithIdentifier("MessageView", owner: self)  as! MessageView!
    var newFrame = cell.messageSubject.frame
    newFrame.size.height = 200
    cell.messageSubject.frame = newFrame
    return cell
}

As you can see the frame for the Subject field remains unaltered.

enter image description here

Interestingly the size of the frame is always the default size set in the Interface builder even when AutoLayout is turned on.

My conclusion is that I'm trying to do this in the wrong method.

I have been able to resize the frame in a simple non-table based viewController with no problem.

iphaaw
  • 6,764
  • 11
  • 58
  • 83
  • What do you mean "I have turned off AutoLayout for the field"? Did you turn it off for the whole NIB? Or what? – Ken Thomases Aug 13 '15 at 23:06
  • I turned off the constraints for the field. – iphaaw Aug 13 '15 at 23:08
  • You deleted them? Marked them to be removed at build time? Disabled them? What **exactly**? Anyway, none of that turns off auto layout for the field. Either Xcode will have added constraints at build time or the field has no constraints but is still subject to auto layout. (The latter would tend to zero its frame, though.) The closest you can come is to set `translatesAutoresizingMaskIntoConstraints` to true programmatically, at which point any frame you set and the `autoresizingMask` are translated into constraints. It will be hard to get the other views to work with that one, though. – Ken Thomases Aug 13 '15 at 23:40

0 Answers0