Post

Replies

Boosts

Views

Activity

Some NSNotification.Name constants are missing when enabling C++ interoperability
When enabling direct C++ interoperability in Xcode, this simple code below NotificationCenter.default.addObserver(self, selector: #selector(subjectAreaDidChange(_:)), name: .AVCaptureDeviceSubjectAreaDidChange, object: nil) gives me the following error Type 'NSNotification.Name?' has no member 'AVCaptureDeviceSubjectAreaDidChange' But if I switch C++ and Objective-C interoperability to just C / Objective-C then the code compiles without errors. The issue seems to affect NSNotification.Name constants only from AVFoundation framework (although there maybe more). Why do I get this error and how do I fix it?
0
0
464
Feb ’24
UITableViewCell layout not updating until cell is reused
I have a UITableView that I fill with autosizing cells. UITableView setup is fairly simple:tableView.estimatedRowHeight = 70 tableView.rowHeight = UITableViewAutomaticDimensionExactly like Apple recommends here: https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithSelf-SizingTableViewCells.htmlTo enable self-sizing table view cells, you must set the table view’s rowHeight property to UITableViewAutomaticDimension. You must also assign a value to the estimatedRowHeight property. As soon as both of these properties are set, the system uses Auto Layout to calculate the row’s actual height.When configuring a cell I also disable/enable some constraints to achieve the needed look. That’s where things get interesting. Cell layout is not updated until the cell is reused. Literally. You can call layoutIfNeeded(), setNeedsLayout(), layoutSubviews() or any other method there is, there is no way you will force the cell to update its layout.All other aspects work pretty good: labels do change their text, you hide/unhide the views, but layout is stuck until the cell is reused.You can find the sample project with the bug here: https://www.dropbox.com/s/vqg0gw0a8ycziyq/ReusedCellBug.zip?dl=0Question: what causes it and how to avoid this behavior?P.S. After playing around I found out that if I completely remove `tableView.estimatedRowHeight = 70`, then layout works as expected, but trying to use autosizing cells without estimatedRowHeight leads to table view putting height constraint on cell's content view (height equals to 43.5 point). In error logs this constraint is the famous'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fd63d508490.height == 43.5 (active)And because my cell's height is not equal to 43.5 points, auto layout decides that this height constraint is more important than my cell's layout and fits my cell content in 43.5 points.So I can't use estimatedRowHeight because it breaks auto layout, but without it my layout also gets broken.how can I safely deprioritize this UIView-Encapsulated-Layout-Heightconstraint? Is there any way I can get autosizing cells without using estimatedRowHeight?
10
1
22k
Nov ’16