NSArrayController, View Based Table, NSPopUpButton and Bindings - macos

I am trying to bind a NSPopUpButton in a view based NSTableView with NSArrayContollers using Xcode 8.1. I have an macOS app that had been using a cell based NSTableView and I would like to convert it to a view based table, however, I have been completely unsuccessful in doing this. I have looked at all the various wed postings, but nothing seems to work for me. I have been working on this for over two days.
Here is my design:
accountArrayController is bound to the larger table and this all seems to work just fine.
patientArrayController is aNSMutableArray of NSString's that contains the list of patients to be populated in the menu items of the NSPopUpButton.
Here are the actual bindings for the NSPopUpButton
I am guessing that the problem is in the Content Values bindings, I have tried many variations. When I compile this, I get
.../xxx.storyboard: Exception while running ibtool: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
However, when I try other variations, Xcode (really ibtool) hangs for a long time and then exits with an error code of 255.
How can I resolve this? I'm happy to provide other binding information and code blocks, if needed.

The model attribute name you used in the NSTableColumn bind, you want to also use in the Table Cell View bind - 3rd level down from table column. It should have filled in already 'objectValue' or 'selection' or 'arrangedObjects', just add . and you should be good.

Related

xcode: Timestamped Event Matching Error: Failed to find matching element

I'm trying to record some XCUITesting functions. I get this error.
Timestamped Event Matching Error: Failed to find matching element
Is this an Xcode bug and/or issues with the complexity of my UI?
I was having the same problem for a long time on a very complex app as well: The key is all in isAccessibilityElement being set to YES. UI testing and accessibility go hand-in-hand. The way I think about it is that the device needs to be able to interact with the element, since ostensibly, the user wouldn't be able to.
I did this twice:
In cellForRowAtIndexPath - cell.isAccessibilityElement = YES
In awakeFromNib in a UITableViewCell subclass - self.isAccessibilityElement = YES
Hope that helps, and good luck!
Try manipulating with items isAccessibilityElement property. As far as I know containers like tableView should have this property set to NO in order to items contained inside them be accessible
Quote from https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAccessibility_Protocol/#//apple_ref/occ/instp/NSObject/isAccessibilityElement :
Assistive applications can get information only about objects that are
represented by accessibility elements. Therefore, if you implement a
custom control or view that should be accessible to users with
disabilities, set this property to YES. The only exception to this
practice is a view that merely serves as a container for other items
that should be accessible.
You need to add key path value to your UI elements as below. For an example, if you are using a tableview then select it in the Storyboard and then click on Identity Inspector. Now enter the following value isAccessibilityElement in the key and tick the checkbox as shown in the image below.
Also if you can't tap on the UITableViewCell or the subclasses, then enable the Accessibility option as shown below.
hereafter it should work just fine.

crash on document close when binding trough one-to-one relationship

Build environment: Xcode 7 beta 7
OS X: 10.10.5
Swift 2
I have a project that is using the BSManagedDocument class from github to wrap core data into an NSDocument. I am using Cocoa bindings to get the data from core data to an NSOutlineView using an NSTree Controller.
The object model is fairly simple. The object (called SourceGroup_ tied to the tree controller has a one-to-many relationship with itself to provide the hierarchical data for the tree controller. It also has an optional one-to-one relationship with a Media object that provides a URL for associated media (image, video, etc.).
The outline view has three columns bound, two are bound to properties of the main object while the third is a thumbnail image that comes from the one-to-one media relationship.
Everything displays fine but someitmes when I close the document I get an EXC_BAD_ACCESS in _NSGetUsingKeyValueGetter that goes back though NSAutoUnbinder and [NSTableCellView release] back through [NSAutoreleasePool drain]. This doesn't happen every time but it does happen occasionally.
It I remove the column that is bound through the one-to-one relationship it never crashes. If I add in a non-core data property on SourceGroup that simply returns the image from the preferredMedia relationship and then bind to that property on SourceGroup, it never crashes.
It doesn't matter what the type of the field is. If I bind through the relationship, it (sometimes) crashes on close, whether it's String or NSImage.
I've even tried generating my core data objects as Objective C rather than Swift but that made no difference in behavior. No matter what I change the one constant is that if I bind the view in the table column through the relationship it sometimes crashes on close. Yet, on the detail side, if I bind to the same fields through the selectionIndex that works fine and never crashes. The crash only occurs if it's in the outline view.
I know the descriptions can be a bit vague so I prepared some screenshots unfortunately I appear to lack enough reputation to share them. I'll try to describe the setup.
The tree controller is in entity mode with the entity set to SourceGroup. It's source descriptors and managed object context are bound to my view controller.
The outline view's content is bound to the tree controller's arrangedObjects controller key. The selectionIndexPaths and sort descriptors are also bound to the tree controller.
The value for the NSImageView in the column is bound to the table cell view with the model key path set to objectValue.preferredMedia.thumbnail.
This all displays properly but causes intermittent problems on closing the document. If I put a thumbnail image property into SourceGroup and then bind that image view to objectValue.thumbnail I never see the issue
I don't see anything in the docs about this type of setup being a problem but I'm also new enough to OS X programming that I may have missed something.
Can anyone see a problem in what I'm trying to do?
I had a similar problem with Core Data, treecontroller and images. The managed object context is released before the outlineview and treecontroller. The context is turning managed objects into faults before the bindings remove their observers.
A workaround is setting the content of the treecontroller to nil when the window will close.

Can't get NSTableView to display any text whatsoever

I've been developing on iOS for some time, but am very new to Cocoa development, and something seemingly very simple is stumping me.
I have an NSTableView, hooked up to a subclass of NSWindowController as both datasource and delegate. I have an array of "File" objects (my model class) and want to populate one column of my tableview with file types, and another with timestamps.
The dataSource methods are definitely being called, as verified by setting breakpoints. In fact, I end up with an appropriate number of rows that are selectable...but none of them display anything. I even tried returning an arbitrary string literal in objectValueForTableColumn, for all rows and columns, and still nothing.
I think I'm probably stuck on how tableViews work in iOS, but obviously they are very different here...I am used to configuring and returning a cell myself, but here we just pass AnyObject??? How exactly does the tableView know how to display AnyObject? I'm really struggling with the conceptual understanding here. Appreciate any help.

UITableView like NSTableView

Ive developed for iOS in the past and recently moved over to mac development. I began a project to "get the feel" of things, and ran into an issue. Im trying to create a NSTableView to display multiple items, including a label, a 2 UIImageViews, and a UIButton. NSTableViews are way different than tables on iOS, and I cant simply create a custom TableViewCell (I think). A great example of how I would like it to look is AlienBlue for Mac: (The middle table with post information)
Can anyone shed some light on how to create this?
You have the power of being able to return whole views instead of cells in NSTableViews.
Here's Apple's documentation on View-based tables and how to populate those views in your table.
The delegate method I use most in my own view-based tables is "tableView:viewForTableColumn:row:"
Hopefully this points you in the right direction!
Please use NSCollectionView instead (set NSCollectionView.maxNumberOfColumns = 1). It's a more modern, extensible view api, that is analogous to UICollectionView.
In contrast, NSTableView was originally meant for displaying a spreadsheet table (with add-on support for custom view cells), and is less consistent with UITableView.

Array Controller not updating Table View until "Add" button is pressed

I'm new to Cocoa and Objective-C, so I'm following the Lynda courses and learning a lot. Thing is, I've encountered a problem that I cannot figure out, even though I seem to be doing it exactly the same way...
Basically, I'm trying to get a Table View hooked up through bindings to an Array Controller, just to list out the contents of a simple NSMutableArray in my code. I'd gotten it all hooked up properly, but no matter what I did it wasn't displaying anything when I ran the program.
Here's where it gets weird: on a lark, I added a "+" button and hooked it into the "add" function of the Array Controller, and when I ran the app and clicked that button, it not only added a new line, but it displayed the whole array as well! Apparently everything had been hooked up properly the whole time, it just wasn't displaying the information. Further experimentation revealed that I could make any changes I wanted to the array, whether in the original code or during the runtime of the app, but they would only be updated in the Table View when I clicked that "+" button.
I feel like this is probably a simple solution, just some "Continuous" box that needs to be checked or something, but I cannot for the life of me find it... Can anyone point out what I need to do to get my TableView to show its contents automatically?
(Also, I don't know if this is related or not, but none of the "Model Key Path" fields in the inspector are offering suggestions as I type, which they do in the Lynda course. The app works fine if I manually type everything in, but it says "no completions found" the whole time.)
Thank you in advance for helping out a n00b!
none of the "Model Key Path" fields in the inspector are offering suggestions as I type
As I understand it this is probably because the NSMutableArray that holds your data array i.e. dogPound or similar, isn't also declared as a property, only an instance variable.
Declare the property #property NSMutableArray * dogPound; and change the instance variable declaration to _dogPound and I think interface builder should offer you the auto-completes.
I'm new to Cocoa and Objective-C
Me too.
I'd gotten it all hooked up properly,
In about 30 minutes, I can get everything setup with a custom class like Dog, and another class called AppController that consists of one instance variable: NSMutableArray* dogPound. The init() method for the AppController class creates the array and adds some Dog instances to the array. I also bound an NSArrayController to the dogPound array, and I bound the NSTableView columns to the NSArrayController. After I Build&Run the NSTableView displays the information for each Dog instance in the dogPound array.
I also tried a simpler version where there is no Dog class and the array in the AppController class just consists of some NSString objects. Once again, I was able to successfully bind an NSArrayController to the array and bind the table's columns to the NSArrayController, so that an NSTableView displayed all the NSString's in the array.
You need to post your exact code, and you need to write down every step you did in IB, which of course is a huge pain in the ass, but it's the only way anyone will be able to help you.
Here's where it gets weird: on a lark, I added a "+" button and hooked
it into the "add" function of the Array Controller, and when I ran the
app and clicked that button, it not only added a new line, but it
displayed the whole array as well!
Of course. The add: method in the NSArrayController adds a new item to the array and then signals the NSTableView that it should reload the data, i.e display everything that's currently in the array.
I feel like this is probably a simple solution, just some "Continuous"
box that needs to be checked or something,
Nope, nothing like that.
none of the "Model Key Path" fields in the inspector are offering
suggestions as I type
Lack of autocompletion choices is a big hint that you are doing something wrong--even though I find I can't always figure it out, so I just keep typing. Did you remember to start your bindings in the Attributes Inspector(Object Controller section) for the NSArrayController? In IB, did you create an instance of your AppController class, or whatever you called the class that contains the NSMutableArray, by dragging an Object onto MainWindow.xib?

Resources