ambiguous use of registerclass with Swift
Your call to registerClass
has a parameter name (cellClass) for the first parameter. In Swift, the first parameter name is omitted.
tableView.registerClass(CustomTableViewCell.self,
forCellReuseIdentifier: "CustomCell")
The reason the error says ambiguous use of registerClass is because the compiler can't tell which one you are trying to call. There are two registerClass
methods on UITableView:
func registerClass(cellClass: AnyClass, forCellReuseIdentifier identifier: String)
func registerClass(aClass: AnyClass, forHeaderFooterViewReuseIdentifier identifier: String)
Your call doesn't match either of these, therefore it's ambiguous.
CoreData/TableView - Ambiguous use of 'subscript'
You have this declaration:
var eventItems: AnyObject?
Then later on you do this:
let eventItem = eventItems! [indexPath.row]
The problem is that you declared eventItems
as AnyObject?
, and AnyObject
does not accept subscripts. It can literally be any object at all, and not every class works with subscripts, so Swift doesn't know what to do.
Since you're assigning eventItems
as the result of a fetch request, it should be declared as either an NSArray?
or as something like [Event]?
. Also, using that !
after eventItems
puts you at serious risk of a crash; don't ever use !
unless you're absolutely sure that you won't accidentally have a nil value.
Converting Objective-C to Swift: Assigning to self
When initializing an object in Swift it is guaranteed to be safe.
Therefore, there is no need to check it for nil values.
UICollectionView items not showing after migration to Swift 2
So it looks like ios9 has a bug when rendering custom cells.
I would suggest creating your custom cells in xibs and then loading them from there.
Make sure to include this in viewDidLoad:
self.collectionView.registerNib(UINib(nibName: "SongCell", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "SongCell")
self.collectionView.registerNib(UINib(nibName: "SongHeader", bundle: NSBundle.mainBundle()), forCellWithReuseIdentifier: "SongHeader")
UITableView with variable cell height: Working in IB but not programmatically
The error is pretty trivial:
Instead of
self.addSubview(myCellLabel)
use
self.contentView.addSubview(myCellLabel)
Also, I would replace
// pin top
NSLayoutConstraint(...).active = true
// pin bottom
NSLayoutConstraint(...).active = true
// center horizontal
NSLayoutConstraint(...).active = true
with
let topConstraint = NSLayoutConstraint(...)
let bottomConstraint = NSLayoutConstraint(...)
let centerConstraint = NSLayoutConstraint(...)
self.contentView.addConstraints([topConstraint, bottomConstraint, centerConstraint])
which is more explicit (you have to specify the constraint owner) and thus safer.
The problem is that when calling active = true
on a constraint, the layout system has to decide to which view it should add the constraints. In your case, because the first common ancestor of contentView
and myCellLabel
is your UITableViewCell
, they were added to your UITableViewCell
, so they were not actually constraining the contentView
(constraints were between siblings not between superview-subview).
Your code actually triggered a console warning:
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
Which made me to look immediately at the way the constraints are created for your label.
Related Topics
How to Update a Swiftui View State from Outside (Uiviewcontroller for Example)
Swift Function That Takes in Array Giving Error: '@Lvalue $T24' Is Not Identical to 'Cgfloat'
Get Section Number in Custom Cell Button Action
Swiftui Card Flip Animation with Two Views, One of Which Is Embedded Within a Stack
Change Uitabbar Tint Colors in the More Menu
No Such Module "Sinch" Xcode 9.1 Swift 4
Swift Link Image from Parse Array Using Segues to Secondviewcontroller
Realmswift Cannot Cast Results<Someojbect> to Results<Object>
How to Update Individual Array Element in Firebase with iOS Swift
Storyboard Localization in Swift 4.0
Uitableview with Different Optional Sections
How to Create a "Hyperlink" with Swift
Sirikit, How to Display Response for Start Workout Intent
Saving Array Using Nsuserdefaults Crashes App