Post

Replies

Boosts

Views

Activity

How to prevent UITextField from intepreting its characters (e.g. converting "..." to elipsis)
Howdy! I am writing validation logic for a UITextField which is heavily dependant on its characters' code points. As such, it is undesirable for this text field to make conversions like it does for three consecutive periods ("..." turns into unicode elipsis ). This is the only example I have encountered thus far, but I would like to disable this feature in its entirity for several reasons. Is there a way to achieve this? Thanks, smkuehnhold
2
0
1.2k
Feb ’22
Any way to horizontally inset the cells of a UITableView?
Howdy, Is it possible to inset the left and right edges of the cells contained within a UITableView? I initially thought that contentInsets would do the trick, but I can't to get this to work. More specifically, it seems that adjusting the contentInsets only affects the scrollable area rather than the area actually occupied by the cells. Are the cells not a part of the content? The only other way I can think of doing this is by embedding the UITableView inside another UIScrollView, which feels like overkill. Is there a better way? Note that I do not want to adjust the bounds of the UITableView because I want the area occupied by the insets to remain scrollable. Thanks, smkuehnhold
2
0
2.6k
Aug ’22
Are IBOutlets set asynchronously to instantiate(withOwner:options:)?
Howdy! I have the following pattern peppered across my code base. Until now, it has worked without any issues. protocol NibBased: UIView {   static var nibName: String { get }   static var nibBundle: Bundle { get }   static var nibOptions: [UINib.OptionsKey: Any]? { get }   static var nibIndex: Int { get }   static func makeFromNib(_ nibOwner: Any?) -> Self } // default impl extension NibBased {   static var nibName: String {     String(describing: Self.self)   }   static var nibBundle: Bundle {     Bundle(for: Self.self)   }   static var nibOptions: [UINib.OptionsKey: Any]? {     nil   }   static var nibIndex: Int {     0   }   static func makeFromNib(_ nibOwner: Any? = nil) -> Self {     UINib(nibName: nibName, bundle: nibBundle)    .instantiate( withOwner: nibOwner, options: nibOptions )[nibIndex] as! Self   } } final class _InternalView1: UIView, NibBased { // impl } final class _InternalView2: UIView, NibBased { // impl } final class ExternalView: UIView { @IBOutlet private weak var viewFromInternal1: UIView! @IBOutlet private weak var viewFromInternal2: UIView! private typealias Internal1 = _InternalView1 private typealias Internal2 = _InternalView2 required init?(coder: NSCoder) { super.init(coder: coder) _init() } override init(frame: CGRect) { super.init(frame: frame) _init() } private func _init() { let view1: InternalView1 = .makeFromNib(self) let view2: InternalView2 = .makeFromNib(self) // place view1 and view 2 in the view hierarchy // impl // configure the views from the internal views viewFromInternal1.backgroundColor = .red viewFromInternal2.backgroundColor = .blue } } The problem I am running into now on a particular view of mine is that some of the internal @IBOutlets remain unset even after calling .makeFromNib(self) to create the internal views and placing them in the view hierarchy. The@IBOutlets that remain unset seems mostly random and appears to be influencable by the debugger, which has be concerned... My assumption until now was that the @IBOutlets would be set when the Nib is intantiated with an owner. Has this assumption been wrong this whole time? Have I inadvertently been relying on a race condition?
3
0
1k
Aug ’22
Updates to view.backgroundColor sometimes not reflected in simulator?
Howdy! I am running into a probem where changing the backgroundColor of an active UIView is sometimes not reflected in the simulator. When this happens, I've been able to confirm via the debugger that the backgroundColor property is being set, but the color that is rendered is not changing! Basically view.backgroundColor could be equal to UIColor.black, but the rendered color remains gray. Can anyone help explain what could possibly be going wrong? Not sure if important, but I have an extreemly simple UIViewController consisting of a single UIView that looks roughly like the following. final class ViewController: UIViewController, Themeable { override func viewDidLoad() { super.viewDidLoad() // basically sets up calls to update(theme:) when UITraitCollection.current changes subscribeToThemePublisher() } // from Themeable func update(theme: any Theme) { guard isViewLoaded else { return } view.backgroundColor = theme.backgroundColor } }
1
0
619
Aug ’22
Why are my equally-constrained UIViews not rendered with the same size?
Howdy! I have a view which is constrained to a height of 0.5 and is reused in several places. When several are rendered near each other however, it becomes clear that their heights are subtly different (but enough to annoy me!). It doesn't appear as if any constraints are breaking. For additional information, I am trying to roughly replecate the appearance of the UITableView seperator in some of my views. Hints on how UIKit manages to ensure that a UITableView's seperators all appear to be the same height will also be appreciated. Thanks, smkuehnhold
6
0
1.2k
Aug ’22
When are @IBOutlets set?
Howdy! FYI This is mostly just a rephrasing of my question from the other week. I have a superview which owns some subviews defined in a XIB. Until now, I have assumed that the @IBOutlet defined in the owner/superview are set during the call to UINib.instantiate(withOwner:options:). Is assumption this incorrect? In practice at least, this assumption seems to mostly hold true. But now I have run into a case where only some of the IBOutlets remain unset even after I instantiate and add to the view hierarchy. What gives? Thanks, smkuehnhold
2
0
1.3k
Aug ’22
Dynamically Reconfigure Visible Title of an IB-based UIViewController before it is Visible
Howdy, I have a storyboard-based view controller which I manually load into memory (i.e. no segues) and push into a navigation stack. For this view controller, I would like to dynamically update the title prior to presentation based on some runtime-state. My initial assumption was that this could be done simply by updating navigationItem.title sometime before viewDidAppear(:). But this procedure is not behaiving quite as I expected. It seems that no matter where I set navigationItem.title, the rendered title is only updated after the view controller is fully pushed. Meaning that the user is able to see the title is changing from its default value as defined in the storyboard to the dynamically generated one. This is not the behavior I want. What is the easiest/correct way to force an update to the visible title before the view controller is presented to the user? Is this even possible? Thanks, smkuehnhold
2
0
892
Oct ’22
Precompute the height of a UITableView with dynamically sized cells
Howdy, I have a UITableView which is embedded deeply (i.e. nested in other views) within another UIScrollView for reasons. It seems that in order to get this outer UIScrollView to scroll properly, I have to constrain the height of this UITableView ahead of time. My problem is that I can't figure out how to calculate this height quickly with dynamically sized cells (thus contentSize and related methods won't work). The best method I have been able to come up with is to scroll to each cell individually and fetch their height ahead of time sometime during/after layout, which is less than ideal... I imagine I could also adjust the height as cells are being loaded, but that doesn't sound like good user experience (scroll view keeps growing, wouldn't it be choppy?). On quick investigation, it seems that a regular (i.e. non-embedded) UITableView is able to get an accurate height of dynamically sized cells ahead of time (as seen by the scroll bar). I'm curious if this means that there is something I am missing? I'm sure there is a lot left for me to learn. I will appreciate any help. Thanks, smkuehnhold
1
0
2.0k
Jan ’23
Changing Build Configuration Results in "No such module" Error
Howdy, I am trying to introduce a new build configuration to an existing project and am seemingly running into issues when trying to link with external packages. In particular, the build fails with the error "No such module <MODULE_NAME>" wherever I try to import said module. Changing back to the Debug/Release build configuration makes this issue go away immediately, so I am pretty sure it is an issue with how I've defined the new build configuration. This seems like it could be something rather simple (correct me if I am wrong), so I will spare details for now. If you could just inform me of general places to look into, that would be very helpful. Xcode Version 14.2 (14C18) Thanks, smkuehnhold
0
1
422
Feb ’23
Core NFC reports stack error in the modal intermittently. What is this error?
Howdy, I seem to have a reliability issue when reading a type 5 tag where I get this "Stack Error", but only sometimes. Other times, the reads are completing without an issue. The delegate's readerSession(:didInvalidateWithError:) is reporting type 200 (user cancelled) even though that doesn't seem to be the case. It looks like Core NFC is cancelling the session itself... What does this mean? Thanks, smkuehnhold
1
0
808
Mar ’23
Alternatives to UINavigationItem backAction for iOS < 16
Howdy, I had the pleasure of discovering the existance of the backAction property in UINavigationItem today 😃. TLDR this property lets you override the behavior of the native back button in a UINavigationController. This feature would be quite convenient for my use case, but unfortunately my app targets iOS 14, so I need an alternative. In the past, I remember being unsatisfied with existing solutions. IIRC the choices were recreating the back button from scratch (more difficult than it looks) or traversing the tree (fragile). Is this is still the case for iOS 14-15 or are there better solutions? Thanks, smkuehnhold
0
0
396
Jun ’23
How to disable scroll animation for UITextField?
Yes, I mean UITextField. Howdy, Is there a way to disable the animation that occurs to a UITextField with long content after it becomes first responder? Specifically the one that sort of slow scrolls to the end of the content. Here's a video of the animation I am trying to describe https://www.youtube.com/watch?v=9l2tUrxW_qY . Notice how the textfield transitions from "a" to "." as it moves to the end of the content? Ideally, I would like the UITextField to simply appear on the screen like it does in the final frame of the animation, showing the final part of the content. Thanks, smkuehnhold
0
0
422
Dec ’23