PXSourceList
PXSourceList copied to clipboard
Badges don't display in view-based cells loaded from a storyboard
For view-based mode, OS X 10.10.3, running Xcode 6.4:
When a PXSourceListTableCellView is designed inside a storyboard, the badge view is never displayed. The same behaviour is seen if loaded from a xib and the "Prefer coder" option is checked in Interface Builder. You can see this behaviour by checking the "Prefer coder" option for the MainMenu.xib in the ViewBasedSourceList demo project.
I believe this is because the underlying PXSourceListBadgeCell is never initialised due to the way the storyboard or nib is loaded via the initWithCoder: path.
Hi, look at this. https://mikeash.com/pyblog/custom-nscells-done-right.html
BTW thanks for filling this issue, I'm not that good in Cocoa and its about a week ago I've stubled upon this issue. Not knowing what caused it was making me mad :D
I'm still not quite sure how to use PXSourceList correctly. Do we have to manually generate the BadgeView in IB and size it? Here is my current process:
- Drag into my MainView a SourceList
- Change the class into PXSourceList or a class derived from PXSourceLIst
- Change the TableCellView that is "DataCell" to "MainCell"
- Change both HeaderCell and MainCell to PXSourceListTableCellView
At this point everything still looks the same as before, and there is no BadgeView in MainCell, not even an outlet. Am I missing something here? @Miirek, did you end up doing that subclass thing in the custom-nscells-done-right link? Should I be manually creating the Badgeview, and hooking up the outlet?
same issue with subclass the PXSourceListTableCellView
func configCell(tag: Tag){
textField?.stringValue = tag.name
imageView?.image = NSImage.fontAwesomeIconWithName(.Tag, textColor: .lightGray, size: CGSize(width: 40, height: 40), backgroundColor: .clear)
badgeView.badgeValue = UInt(tag.starsCount)
badgeView.isHidden = tag.likeCount == 0
badgeView.textColor = .red
badgeView.backgroundColor = .blue
}
I just found a tricky approach that works fine for me (Swift 4, storyboard)
- Create a subclass of PXSourceListTableCellView, such as LCSourceListTableCellView.
- Add a label "badge" with @IBOutlet into the new cell view in order to replace the badgeView
- In Interface Builder, change the class of table cell view of DataCell from PXSourceListTableCellView to LCSourceListTableCellView
- In Interface Builder, connect the "badge" outlet to the table cell view above, just as what we did for PXSourceListTableCellView
- In the func sourceList(_ aSourceList:PXSourceList!, viewForItem item: Any!) , change the type of cellView to LCSourceListTableCellView for DataCell, set the numbers into the title property of the label "badge" instead of the old "badgeView"
- Override layout() in LCSourceListTableCellView, set the colors and corner radius for the label as what you like