alexrozanski / PXSourceList

Source List control for the Mac
Other
639 stars 77 forks source link

Badges don't display in view-based cells loaded from a storyboard #53

Open graemesi opened 9 years ago

graemesi commented 9 years ago

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.

Miirek commented 9 years ago

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

tofutim commented 8 years ago

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:

  1. Drag into my MainView a SourceList
  2. Change the class into PXSourceList or a class derived from PXSourceLIst
  3. Change the TableCellView that is "DataCell" to "MainCell"
  4. 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?

HamGuy commented 7 years ago

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
    }
kelvinjjwong commented 6 years ago

I just found a tricky approach that works fine for me (Swift 4, storyboard)

  1. Create a subclass of PXSourceListTableCellView, such as LCSourceListTableCellView.
  2. Add a label "badge" with @IBOutlet into the new cell view in order to replace the badgeView
  3. In Interface Builder, change the class of table cell view of DataCell from PXSourceListTableCellView to LCSourceListTableCellView
  4. In Interface Builder, connect the "badge" outlet to the table cell view above, just as what we did for PXSourceListTableCellView
  5. 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"
  6. Override layout() in LCSourceListTableCellView, set the colors and corner radius for the label as what you like