3

I have a single column NSTableView (view based) with a TextField. I am using autolayout and IB. Most of the views in the window are resizable, in particular the table. I am putting attributed text in the TextField. If the application starts with the table width smaller or equal to the width of the TextField (as specified in IB), then everything works great. On the other hand, if the table is initially presented too wide, then the TextField is too small and the text wraps leaving a large amount of left hand space. Resizing the table automatically corrects the TextField width, until the application is restarted.

Inside tableView viewForTableColumn I get an NSTableCellView with the standard makeViewWithIdentifier. I tried forcing the frame size larger, but that had no effect. The frame matches the values from the nib (as one would expect). The only constraints are on the Table Cell View, which force it to grow and shrink with the table resizing, BUT only after the table width is shrunk by the user.

Is there something going on with the Bordered Scroll View that holds the table? Where would I force the NSTableCellView to reconcile its width?

before manual resize by user: before user resizes

after resizing: after user resizes

Thanks...

Bill
  • 1,588
  • 12
  • 21
  • I am having this exact same problem! So frustrating that it works perfectly after resizing. Was your solution just to recreate the xib file? – DouglasHeriot Jun 19 '15 at 07:46

6 Answers6

0

The width of a cell in a tableview is defined by the width of the tableColumn, the height respective in the row height. You can't change it only for specific cell. Scrollview <-> Tableview They are used together, but have very different tasks. Think of the tableview as a picture, that is shown in a window = scrollview. If the picture is to large for the window, you can use the scrolls to make the invisible parts visible. Tableviews often are to large...

macrene
  • 198
  • 1
  • 8
  • I'm not making this clear. I want all the cells at the same width. The problem is in the initial presentation the cells are narrow compared to the tableColumn. Once the tableColumn is resized smaller then the cells grow and shrink with the tableColumn. The cells start out not matching the width of the tableColumn. – Bill Mar 05 '14 at 17:32
  • I understand, that the text cells' width is not synchronize to the table column's width, when the tableView is presented the first time. After manual resizing it works. You have to check, when the cell size in your code is set. Insert a log "NSLog(@"methodname") to find out, when the method is called. It must be called, when the tableView is gathering all information (content, formatting, etc.) of a cell to present it in the correct way. Some code here would help analyzing... – macrene Mar 06 '14 at 14:19
0

In the documentation look for "Cocoa Tips and Tricks", that is some sample projects and you find some files with "TableViewVariableRowHeights...". Download the projects. In the your folder used for the download you find the a folder "TableViewVariableRowHeights". The needed code is easy to find. Good luck.

macrene
  • 198
  • 1
  • 8
0

Thank you @macrene for the useful suggestions. Most of my debugging kept pointing to a faulty nib, which indeed seems to be the case.

I can't say "I understand the problem", but my application is working. There seems to be some issues with IB and having two tables in the same view. I created a test case application with just one table and everything was working. But I noticed some "weirdness" when trying to resize the table in IB. Sometimes the table would just move off to a corner out of sight.

I went back to my application and deleted the table with the problems after trying to match the constraints against my test case since IB wouldn't let me enter the same constraints. I had to place the table using the size inspector. I kept clearing all constraints and playing with it. I finally somehow got the constraints to enter.

The hierarchy is:

View
  Bordered Scroll View - Table View
    Clip View
      Table View
        Table Column
          Table Cell View (need constraints here)
            Text Field - Table View Cell (need constraints here)
            Text Field Cell - Text Cell

My guess is that IB gets confused when there are two tables in the same view. It certainly has problems with adjusting the size and position of the tables via mouse.

I think there was also some issues with the autoresizingMask. I tried to match those settings by editing the xml version of the nib. I missed something and finally lost patience.

Bill
  • 1,588
  • 12
  • 21
0

I am using two tableViews in the same (window->)view without any problem. Important is, that you have two different connectors, data sources and - if desired - array controllers. You can even create different classes for each tv, if your tvs show different contents.

RESIZING: When using a tableView, be aware, there is a scrollview on top. The hierarchy is 1. ScrollView (inside the window->view, or whatever view the tableview(!) is positioned in. 1.1. TableView (inside scrollView.) Pay attention to IB-Inspector when you setup autosizing for these views. They can be set inside = view itself and outside view->superview. Play with it for the a. sv b. tv -1. inside, 2. outside, 3. combined, watch the red caret in the preview. Use CMD r to preview the settings in IB, then change the size of the window, check, what changes, it's fairly easy to understand.

As you might have seen you can set constraints for the width of a cell in IB. You can change that in your code.

macrene
  • 198
  • 1
  • 8
0

I faced the same problem too.

The solution for me was to make the Table Column Width in the Size inspector the same as the Width for the Table View because for some reason it was 4pt smaller in my case.

arturgrigor
  • 9,361
  • 4
  • 31
  • 31
0

Just ran across a similar problem with XCode 12.5. A cell in an NSTableView that was in a xib that was built with an earlier version of Xcode started only filling ~1/2 of the column width after any modification was made to the xib even if the change had nothing remotely to do with the NSTableView. A diff between the working xib and the slightly modified one (only changed one dimension of another control by 1 pixel) showed 27 changes all over the document, mostly slight pixel changes all through the xib. No amount of fidgeting with constraints would fix this. By sheer luck I happened to discover that somehow the TableView's "Style" in the Attributes panel had changed to "Automatic" when the xib was modified with a later version of XCode. Changing the style to "Full Width" makes the cell fill the whole column.

Chris Walken
  • 378
  • 1
  • 9
  • This seems to match my experience. It's frustrating because prototyping doesn't show the problem. – Bill Jan 06 '22 at 22:13