Construct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.

UIKit Documentation

Posts under UIKit tag

712 Posts
Sort by:
Post not yet marked as solved
2 Replies
228 Views
Hi all apple devs! I am a young developer who is completely new to everything programming. I am currently trying to develop an app where I want to use visionkit, but I can't for the life of me figure out how to implement its features. I've been stuck on this for several days, so I am now resorting to asking all of you experts for help! Your assistance would be immensely appreciated! I started to develop the app trying to exclusively use swiftUI to futureproof my app. Upon figuring out what visionkit is, to my understanding it is more compatible with UIkit? So I rewrote the part of my code that will use visionkit into a UIkit based view, to simplify the integration of visionkits features. It might just have overcomplicated my code? Can visionkit be easily implemented using only swiftUI? I noticed in the demo on the video tutorial the code is in a viewcontroller not a contentview, is this what makes my image unresponsive? My image is not interactable like her demo in the video, where in my code do I go wrong? Help a noob out! The desired user flow is like this: User selects an image through the "Open camera" or "Open Camera Roll" buttons. Upon selection the UIkit based view opens and the selected image is displayed on it. (This is where I want to implement visionkit features) User interacts with the image by touching on it, if touching on a subject, the subject should be lifted out of the rest of the image and be assigned to the editedImage, which in turn displays only the subject without the background on the contentview. (For now the image is assigned to editedimage by longpressing without any subjectlifting since I cant get visionkit to work as I want) Anyways, here's a code snippet of my peculiar effort to implement subject lifting and visionkit into my app:
Posted
by emol.
Last updated
.
Post not yet marked as solved
0 Replies
126 Views
We are developing an cross platform Enterprise grade application in MAUI. Net for our Organization and while displaying alerts using UIAlertController, alerts are displayed along with App Icon with not available symbol on top of it in MacOS. We are generating the iPadOS apps and generating M1 Mac packages using productbuild command and deploying them to mac books. Under Show Package content I can see the app file is having this image and by default it showing this icon. Is there any possibility to generate packages without this icon? In UIAlertController is there any possibility to hide the app icon as it coming by default without mentioning to display the icon I am looking for removing the not available symbol on top of our logo or is there any possibility to hide the app icon from UIAlertcontroller as I m not seeing any options to remove this. Thanks Ranga
Posted Last updated
.
Post not yet marked as solved
1 Replies
138 Views
The following is a UIKit app that uses a collection view with list layout and a diffable data source. It displays one section that has 10 empty cells and then final cell whose content view contains a text view, that is pinned to the content view's layout margins guide. The text view's scrolling is set to false, so that the line collectionView.selfSizingInvalidation = .enabledIncludingConstraints will succeed at making the text view's cell resize automatically and animatedly as the text changes. import UIKit class ViewController: UIViewController { var collectionView: UICollectionView! var dataSource: UICollectionViewDiffableDataSource<String, Int>! let textView: UITextView = { let tv = UITextView() tv.text = "Text" tv.isScrollEnabled = false return tv }() override func viewDidLoad() { super.viewDidLoad() configureHierarchy() configureDataSource() if #available(iOS 16.0, *) { collectionView.selfSizingInvalidation = .enabledIncludingConstraints } } func configureHierarchy() { collectionView = .init(frame: .zero, collectionViewLayout: createLayout()) view.addSubview(collectionView) collectionView.frame = view.bounds collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] } func createLayout() -> UICollectionViewLayout { let configuration = UICollectionLayoutListConfiguration(appearance: .insetGrouped) return UICollectionViewCompositionalLayout.list(using: configuration) } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, Int> { _, _, _ in } let textViewCellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, Int> { [weak self] cell, _, _ in guard let self else { return } cell.contentView.addSubview(textView) textView.pin(to: cell.contentView.layoutMarginsGuide) } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in if indexPath.row == 10 { collectionView.dequeueConfiguredReusableCell(using: textViewCellRegistration, for: indexPath, item: itemIdentifier) } else { collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } } var snapshot = NSDiffableDataSourceSnapshot<String, Int>() snapshot.appendSections(["section"]) snapshot.appendItems(Array(0...10)) dataSource.apply(snapshot) } } extension UIView { func pin( to object: CanBePinnedTo, top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0 ) { self.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.topAnchor.constraint(equalTo: object.topAnchor, constant: top), self.bottomAnchor.constraint(equalTo: object.bottomAnchor, constant: bottom), self.leadingAnchor.constraint(equalTo: object.leadingAnchor, constant: leading), self.trailingAnchor.constraint(equalTo: object.trailingAnchor, constant: trailing), ]) } } @MainActor protocol CanBePinnedTo { var topAnchor: NSLayoutYAxisAnchor { get } var bottomAnchor: NSLayoutYAxisAnchor { get } var leadingAnchor: NSLayoutXAxisAnchor { get } var trailingAnchor: NSLayoutXAxisAnchor { get } } extension UIView: CanBePinnedTo { } extension UILayoutGuide: CanBePinnedTo { } How do I make the UI move to accomodate the keyboard once you tap on the text view and also when the text view changes size, by activating the view.keyboardLayoutGuide.topAnchor constraint, as shown in the WWDC21 video "Your guide to keyboard layout"? My code does not resize the text view on iOS 15, only on iOS 16+, so clearly the solution may allow the UI to adjust to text view changes on iOS 16+ only. Recommended, modern, approach: Not recommended, old, approach: I've tried to say view.keyboardLayoutGuide.topAnchor.constraint(equalTo: textView.bottomAnchor).isActive = true in the text view cell registration, as well as view.keyboardLayoutGuide.topAnchor.constraint(equalTo: collectionView.bottomAnchor).isActive = true in viewDidLoad(), but both of these approaches fail (Xcode 15.3 iPhone 15 Pro simulator with iOS 17.4, physical iPhone SE on iOS 15.8).
Posted
by Filippo02.
Last updated
.
Post marked as solved
1 Replies
132 Views
The following UIKit swift app uses a table view with 2 sections. The first section displays a custom cell with a text view, which was added to the cell’s contentView and anchored to the ladder’s layoutMarginsGuide’s top, bottom, leading and trailing anchors. The second section displays a custom cell that is like the former but with a text field instead of a text view. Both sections have titles defined in the tableView(_:cellForRowAt:) method. If you run the app, you will see that the text view’s text is not vertically aligned to it’s section’s title, whereas the text field’s is. How do I align the text view’s text as well? import UIKit class ViewController: UIViewController { let tableView = UITableView() override func viewDidLoad() { super.viewDidLoad() view.addSubview(tableView) tableView.frame = view.bounds tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight] tableView.dataSource = self tableView.register(TextViewCell.self, forCellReuseIdentifier: TextViewCell.identifier) tableView.register(TextFieldCell.self, forCellReuseIdentifier: TextFieldCell.identifier) } } extension ViewController: UITableViewDataSource { func numberOfSections(in tableView: UITableView) -> Int { 2 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 1 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if indexPath.section == 0 { tableView.dequeueReusableCell(withIdentifier: TextViewCell.identifier, for: indexPath) } else { tableView.dequeueReusableCell(withIdentifier: TextFieldCell.identifier, for: indexPath) } } func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { "Title \(section)" } } extension UITableViewCell { static var identifier: String { "\(Self.self)" } } class TextViewCell: UITableViewCell { let textView: UITextView = { let tv = UITextView() tv.text = "Text view" tv.font = .preferredFont(forTextStyle: .title2) tv.backgroundColor = .systemRed tv.isScrollEnabled = false return tv }() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) contentView.addSubview(textView) textView.pin(to: contentView.layoutMarginsGuide) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } class TextFieldCell: UITableViewCell { let textField: UITextField = { let tf = UITextField() tf.text = "Text field" tf.backgroundColor = .systemBlue return tf }() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) contentView.addSubview(textField) textField.pin(to: contentView.layoutMarginsGuide) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } Here's how the pin(to:) function is defined in case you're wondering: import UIKit extension UIView { func pin( to object: CanBePinnedTo, top: CGFloat = 0, bottom: CGFloat = 0, leading: CGFloat = 0, trailing: CGFloat = 0 ) { self.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ self.topAnchor.constraint(equalTo: object.topAnchor, constant: top), self.bottomAnchor.constraint(equalTo: object.bottomAnchor, constant: bottom), self.leadingAnchor.constraint(equalTo: object.leadingAnchor, constant: leading), self.trailingAnchor.constraint(equalTo: object.trailingAnchor, constant: trailing), ]) } } @MainActor protocol CanBePinnedTo { var topAnchor: NSLayoutYAxisAnchor { get } var bottomAnchor: NSLayoutYAxisAnchor { get } var leadingAnchor: NSLayoutXAxisAnchor { get } var trailingAnchor: NSLayoutXAxisAnchor { get } } extension UIView: CanBePinnedTo { } extension UILayoutGuide: CanBePinnedTo { }
Posted
by Filippo02.
Last updated
.
Post not yet marked as solved
0 Replies
147 Views
Hi everyone! Anyone else seeing crashes like this: Fatal Exception: NSInvalidArgumentException. -[_UISnapshotWindow actualSceneBounds]: unrecognized selector sent to instance I'm encountering a crash within 3-4 seconds of launching my iOS app specifically on devices running iOS 14. The crash log indicates an NSInvalidArgumentException with the following message: `Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x129754 __exceptionPreprocess 1 libobjc.A.dylib 0x287a8 objc_exception_throw 2 CoreFoundation 0x2cc3c -[NSOrderedSet initWithSet:copyItems:] 3 UIKitCore 0xc01ea0 -[UIResponder doesNotRecognizeSelector:] 4 CoreFoundation 0x12c2ac ___forwarding___ 5 CoreFoundation 0x12e5b0 _CF_forwarding_prep_0 6 UIKitCore 0xa918cc -[UIUndoGestureInteraction didMoveToView:] 7 UIKitCore 0x11099b4 _setInteractionView 8 UIKitCore 0x11098bc -[UIView(Dragging) addInteraction:] 9 UIKitCore 0xe9d678 -[UIEditingOverlayViewController _addInteractions] 10 UIKitCore 0x4a73e4 -[UIViewController _setViewAppearState:isAnimating:] 11 UIKitCore 0x4a7910 __52-[UIViewController _setViewAppearState:isAnimating:]_block_invoke 12 CoreFoundation 0xa75bc __NSARRAY_IS_CALLING_OUT_TO_A_BLOCK__ 13 CoreFoundation 0x2410 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] 14 UIKitCore 0x4a75ac -[UIViewController _setViewAppearState:isAnimating:] 15 UIKitCore 0x4a7dc0 -[UIViewController __viewDidAppear:] 16 UIKitCore 0x4a9964 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke 17 UIKitCore 0x4a873c -[UIViewController _executeAfterAppearanceBlock] 18 UIKitCore 0xbda7c4 _runAfterCACommitDeferredBlocks 19 UIKitCore 0xbc903c _cleanUpAfterCAFlushAndRunDeferredBlocks 20 UIKitCore 0xbfcf10 _afterCACommitHandler 21 CoreFoundation 0xa25e0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ 22 CoreFoundation 0x9c704 __CFRunLoopDoObservers 23 CoreFoundation 0x9ccb0 __CFRunLoopRun 24 CoreFoundation 0x9c360 CFRunLoopRunSpecific 25 GraphicsServices 0x3734 GSEventRunModal 26 UIKitCore 0xbca584 -[UIApplication _run] 27 UIKitCore 0xbcfdf4 UIApplicationMain 28 JobLogic 0x1d9ac4 main + 14 (main.m:14) 29 libdyld.dylib 0x1cf8 start` Here's what I've observed: The crash consistently occurs within 3-4 seconds of app launch on iOS 14 devices. I'm seeking assistance with: Understanding the Cause: Any insights into potential causes of this crash, particularly related to _[_UISnapshotWindow actualSceneBounds] and its interaction with iOS 14, would be greatly appreciated. Replication Steps: If possible, guidance on how to reliably replicate the crash on a development device would be extremely helpful for debugging purposes. Solutions: Any suggestions or known workarounds to address this specific crash or similar issues in iOS 14 would be invaluable.
Posted
by M_Hamza.
Last updated
.
Post not yet marked as solved
1 Replies
166 Views
I'm trying to get voiceover to announce accessibility label for UIActivityViewController (for a share sheet that pops up on clicking share button) before the focus goes to one of activity items inside the UIActivityViewController. In order to achieve the above behavior, I'm just assigning accessibilityLabel for UIActivityViewController's view. But looks like I'm not able to override the default accessibility implementation of UIActivityViewController. Is there any way we could override the existing accessibility behavior of UIActivityViewController and announce accessibility label for share options? Thanks in advance!!
Posted Last updated
.
Post not yet marked as solved
0 Replies
101 Views
I tried to create the demo with the code import UIKit class ViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate { override func viewDidLoad() { super.viewDidLoad() self.browserUserInterfaceStyle = .dark let button = UIBarButtonItem(title: "First", style: .plain, target: nil, action: #selector(action(_:))) let button2 = UIBarButtonItem(title: "Second", style: .plain, target: nil, action: #selector(action(_:))) self.additionalLeadingNavigationBarButtonItems = [button, button2] } @objc func action(_ sender: UIBarButtonItem) { showAlert(with: sender) } func showAlert(with button: UIBarButtonItem) { let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) let action = UIAlertAction(title: "Test", style: .default) controller.addAction(action) controller.addAction(action) let presentationPopover = controller.popoverPresentationController presentationPopover?.sourceItem = button present(controller, animated: true) } } But the action sheet is in the wrong position when the user taps the button bar. This issue only happens when the user switches between the share and recent options before tapping the bar button.
Posted Last updated
.
Post not yet marked as solved
0 Replies
127 Views
extension UIView { func takeSnapshot(rect : CGRect? = CGRect.zero) -&gt; UIImage? { let renderer = UIGraphicsImageRenderer(size: frame.size) var image = renderer.image { _ in drawHierarchy(in: bounds, afterScreenUpdates: true) } if let imageRect = rect, imageRect != CGRect.zero { let screenshotFrame = CGRect(x: imageRect.origin.x * UIScreen.main.scale, y: imageRect.origin.y * UIScreen.main.scale, width: imageRect.size.width * UIScreen.main.scale, height: imageRect.size.height * UIScreen.main.scale) let imageRef = image.cgImage!.cropping(to: screenshotFrame) image = UIImage.init(cgImage: imageRef!, scale: image.scale, orientation: image.imageOrientation) } UIGraphicsEndImageContext() return image } } which was working fine until I updated to macOS 14.4.1 from 14.2.1 and to Xcode 15.3 from 15.0. issue From my Mac Catalyst app, if I try to take screenshot of imageView, the screenshot is brighter. If I try this method it seems working: func takeSnapshotWithoutScale() -&gt; UIImage? { UIGraphicsBeginImageContextWithOptions(self.frame.size, false, 0) if let currentContext = UIGraphicsGetCurrentContext() { self.layer.render(in: currentContext) } let newImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return newImage }
Posted Last updated
.
Post not yet marked as solved
0 Replies
287 Views
Though I cannot find any documentation, it seems that UIPasteboard cannot be used from a Quick Look Preview app extension. I have such an extension, which contains a view that supports copying text as follows: - (IBAction)copy:(nullable id)sender { UIPasteboard * pboard = UIPasteboard.generalPasteboard; pboard.string = _rep.text; } This is invoked from a context menu (edit menu) item. This works fine In the simulator, but on device the pasteboard remains empty and errors like the following are emitted: -[PBServerConnection pasteboardWithName:createIfNeeded:authenticationBlock:dataOwnerBlock:error:] failed with error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.pasteboard.pasted was invalidated: failed at lookup with error 159 - Sandbox restriction." UserInfo={NSDebugDescription=The connection to service named com.apple.pasteboard.pasted was invalidated: failed at lookup with error 159 - Sandbox restriction.} It's unclear to me why such functionality would be problematic and necessary to block. It would be nice if this were documented clearly, as I wasted a lot of time trying to figure out why this was not working. (And no, I have not filed a feedback report or TSI yet, as I'm presently very short on time, and I don't have a sample project prepared to demonstrate the issue.)
Posted Last updated
.
Post marked as solved
6 Replies
220 Views
Hi together, i have truble to parse an json with an array like following: "data": [ [ 0000000000, [ { "count": 0 } ] ], [ 0000000000, [ { "count": 0 } ] ] ], Can someone help me to parse that with the this? Thanks
Posted
by clemens68.
Last updated
.
Post marked as solved
1 Replies
188 Views
Hi, developers! I use DiffableDataSource for myTableView and was surprised when I found that TableView in this case caches previously created cells after (or before) a new update. It seems that this is implemented to store cell states and quickly update if the contents of the table change. Because of this mechanism, I have the following problem: my cells use reference-type view models, which in turn contain notification observers from the file upload service. The view model is connected to the cell with a closure, which is called upon notification and updates, for example, the progress scale in the cell After uploading the file, I make a new applySnapshot using similar models with cameras (but, for example, the "fileName" field is already different, so I need to change it in cell). Due to caching of cells in memory, the old view models with observers are not released, as a result, I get two observers, for two different cells, one of which is visible, and the second is not. This causes problems with UI. To summarize, my question is, is it possible to disable cell caching or clean the cache if using Diffable Data Source manually?
Posted
by sahabov.
Last updated
.
Post not yet marked as solved
2 Replies
227 Views
This is to see if anyone knows how to resolve this incident in the new version of XCODE 15.3 since it works fine in version 15.1 As you can see, when you open the component, the text type appears by default and the added library does not load nunitosan, when change to customs and search the font, it does not appear in the list. I would greatly appreciate any TIP or solution for this error in updating the tool.
Posted
by WAG9024.
Last updated
.
Post marked as Apple Recommended
239 Views
How can I open the user's Health Privacy Settings directly from my app when I'd like them to review them? I believe similar questions have been asked before like this one: https://forums.developer.apple.com/forums/thread/730434 However, I'm wondering if the situation is changed for iOS 17 or if there's a way that works for Health permissions. This is directly possible in the Garmin Connect app for example which is a major app on the store.
Posted Last updated
.
Post marked as solved
1 Replies
145 Views
Please run the following UIKit app. It displays a collection view with compositional layout (list layout) and diffable data source. import UIKit class ViewController: UIViewController { var bool = false { didSet { var snapshot = dataSource.snapshot() snapshot.reconfigureItems(snapshot.itemIdentifiers) dataSource.apply(snapshot, animatingDifferences: true) } } var collectionView: UICollectionView! var dataSource: UICollectionViewDiffableDataSource<String, String>! var snapshot: NSDiffableDataSourceSnapshot<String, String> { var snapshot = NSDiffableDataSourceSnapshot<String, String>() snapshot.appendSections(["section"]) snapshot.appendItems(["id"]) return snapshot } override func viewDidLoad() { super.viewDidLoad() configureHierarchy() configureDataSource() } func configureHierarchy() { collectionView = .init(frame: view.bounds, collectionViewLayout: createLayout()) view.addSubview(collectionView) collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight] } func createLayout() -> UICollectionViewLayout { let configuration = UICollectionLayoutListConfiguration(appearance: .insetGrouped) return UICollectionViewCompositionalLayout.list(using: configuration) } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { [weak self] cell, indexPath, itemIdentifier in guard let self else { return } let _switch = UISwitch() cell.accessories = [ .customView(configuration: .init( customView: _switch, placement: .trailing()) ), // .disclosureIndicator() ] _switch.isOn = bool _switch.addTarget(self, action: #selector(toggleBool), for: .valueChanged) } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } dataSource.apply(self.snapshot, animatingDifferences: false) } @objc func toggleBool() { bool.toggle() } } When you tap on the switch, it lags. If you uncomment .disclosureIndicator() and tap on the switch, it doesn't lag. How do I make it so that the switch doesn't lag without having a disclosure indicator in the cell? Note: while it would solve the issue, I would prefer not to declare the switch at the class level, as I don't want to declare all my controls, which could be quite a lot, at the view controller level in my real app. Edit: declaring the switch at the configureDataSource() level also fixes it, but it would still be inconvenient to declare many switches, say of a list with n elements, at that level.
Posted
by Filippo02.
Last updated
.
Post marked as solved
1 Replies
231 Views
If you run the following UIKit app and tap the view controller's right bar button item, the footerText property will change. How should I update the collection view's footer to display the updated footerText? class ViewController: UIViewController { var collectionView: UICollectionView! var footerText = "Initial footer text" var dataSource: UICollectionViewDiffableDataSource<Section, String>! var snapshot: NSDiffableDataSourceSnapshot<Section, String> { var snapshot = NSDiffableDataSourceSnapshot<Section, String>() snapshot.appendSections(Section.allCases) snapshot.appendItems(["A", "a"], toSection: .first) return snapshot } enum Section: CaseIterable { case first } override func viewDidLoad() { super.viewDidLoad() configureHierarchy() configureDataSource() } func configureHierarchy() { navigationItem.rightBarButtonItem = .init(title: "Change footer text", style: .plain, target: self, action: #selector(changeFooterText)) collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: createLayout()) view.addSubview(collectionView) collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth] } @objc func changeFooterText() { footerText = "Secondary footer text" } func configureDataSource() { let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, String> { cell, indexPath, itemIdentifier in var contentConfiguration = UIListContentConfiguration.cell() contentConfiguration.text = itemIdentifier cell.contentConfiguration = contentConfiguration } dataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier) } configureSupplementaryViewProvider() dataSource.apply(self.snapshot) } func configureSupplementaryViewProvider() { let headerRegistration = UICollectionView.SupplementaryRegistration<UICollectionViewListCell>(elementKind: UICollectionView.elementKindSectionHeader) { headerView, elementKind, indexPath in var contentConfiguration = UIListContentConfiguration.cell() contentConfiguration.text = "Header \(indexPath.section)" headerView.contentConfiguration = contentConfiguration } let footerRegistration = UICollectionView.SupplementaryRegistration<UICollectionViewListCell>(elementKind: UICollectionView.elementKindSectionFooter) { [weak self] headerView, elementKind, indexPath in guard let self else { return } var contentConfiguration = UIListContentConfiguration.cell() contentConfiguration.text = self.footerText headerView.contentConfiguration = contentConfiguration } dataSource.supplementaryViewProvider = { collectionView, kind, indexPath in if kind == UICollectionView.elementKindSectionHeader { collectionView.dequeueConfiguredReusableSupplementary(using: headerRegistration, for: indexPath) } else if kind == UICollectionView.elementKindSectionFooter { collectionView.dequeueConfiguredReusableSupplementary(using: footerRegistration, for: indexPath) } else { nil } } } func createLayout() -> UICollectionViewLayout { UICollectionViewCompositionalLayout { section, layoutEnvironment in var config = UICollectionLayoutListConfiguration(appearance: .insetGrouped) config.headerMode = .supplementary config.footerMode = .supplementary return NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) } } } What I've tried to do in footerText's didSet: Reconfiguring the supplementary view provider: var footerText = "Initial footer text" { didSet { configureSupplementaryViewProvider() } } Also re-applying the snapshot: var footerText = "Initial footer text" { didSet { configureSupplementaryViewProvider() dataSource.apply(self.snapshot) } } Also re-configuring the items: var footerText = "Initial footer text" { didSet { configureSupplementaryViewProvider() dataSource.apply(self.snapshot, animatingDifferences: true) var snapshot = dataSource.snapshot() snapshot.reconfigureItems(snapshot.itemIdentifiers) dataSource.apply(snapshot, animatingDifferences: false) } }
Posted
by Filippo02.
Last updated
.
Post not yet marked as solved
3 Replies
307 Views
I have an application that needs to make a USSD call, but on some devices the * and # don't work on the dialer, on others it does. if let phoneNumber = ussdNumberTextfield.text { let encoded = "telprompt:\(phoneNumber)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! if let url = URL(string: encoded) { if application.canOpenURL(url){ DispatchQueue.main.async { self.application.open(url, options: [:]) { success in } } } } }
Posted
by Regadas.
Last updated
.
Post not yet marked as solved
1 Replies
199 Views
This crash happens online and cannot be tested and reproduced. I need help. Thank you very much. Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x000000018b4190d0 Exception Note: EXC_CORPSE_NOTIFY Termination Reason: SIGNAL 5 Trace/BPT trap: 5 Terminating Process: exc handler [338] Triggered by Thread: 7 Last Exception Backtrace: 0 CoreFoundation 0x180cd7c60 __exceptionPreprocess + 216 (NSException.m:200) 1 libobjc.A.dylib 0x198507ee4 objc_exception_throw + 56 (objc-exception.mm:565) 2 CoreAutoLayout 0x1987cb000 _AssertAutoLayoutOnAllowedThreadsOnly + 412 (NSISEngine.m:0) 3 CoreAutoLayout 0x1987cdb7c -[NSISEngine withBehaviors:performModifications:] + 32 (NSISEngine.m:1975) 4 UIKitCore 0x1831262fc -[UIView _resetLayoutEngineHostConstraints] + 80 (NSLayoutConstraint_UIKitAdditions.m:1426) 5 UIKitCore 0x1830fc0c0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2376 (UIView.m:18416) 6 QuartzCore 0x18477c520 CA::Layer::layout_if_needed(CA::Transaction*) + 528 (CALayer.mm:10118) 7 QuartzCore 0x18476f294 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 132 (CALayer.mm:2480) 8 QuartzCore 0x184782cc8 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 464 (CAContextInternal.mm:2612) 9 QuartzCore 0x18478b79c CA::Transaction::commit() + 708 (CATransactionInternal.mm:449) 10 QuartzCore 0x1847dfe04 CA::Transaction::release_thread(void*) + 224 (CATransactionInternal.mm:651) 11 libsystem_pthread.dylib 0x1dc052d90 _pthread_tsd_cleanup + 520 (pthread_tsd.c:388) 12 libsystem_pthread.dylib 0x1dc055c08 _pthread_exit + 80 (pthread.c:1717) 13 libsystem_pthread.dylib 0x1dc05124c _pthread_wqthread_exit + 100 (pthread.c:2559) 14 libsystem_pthread.dylib 0x1dc050e88 _pthread_wqthread + 420 (pthread.c:2593) 15 libsystem_pthread.dylib 0x1dc05092c start_wqthread + 8 (:-1)
Posted
by may0001.
Last updated
.
Post not yet marked as solved
1 Replies
167 Views
Hello, Is there any way to iterate all views and subviews in current xcode app and taget to particular properties to every UIButton. I tried using folllowing code but it is not working. for views in self.view.subviews { if views == UIButton { button.isPointerInteractionEnabled = true } else { } }
Posted Last updated
.
Post not yet marked as solved
0 Replies
191 Views
First of all, I decided to make my project with only UIKit. So I deleted 'Main' storyboard, Info.plist->Storyboard name, and Main storyboard file base name->Main. And I edited SceneDelegate. So now I can display the single viewControllers, but when I try to set 'UITabBarController' to rootViewController, It cause this error(title). I tried to make UITabBarController in ViewController, UITabBarController in SceneDelegate and some more. // BackgroundViewController for the rootViewController import UIKit class BackgroundViewController: UIViewController { let backgroundTabBarController = UITabBarController() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white createTabBar() } } extension BackgroundViewController { private func createTabBar() { view.backgroundColor = .white view.addSubview(backgroundTabBarController.view) let firstViewController = BookSearchViewController() let secondViewController = MainViewController() let thirdViewController = UserStatusViewController() let lastViewController = OrderViewController() firstViewController.tabBarItem = UITabBarItem(title: "Search", image: UIImage(systemName: "magnifyingglass.circle.fill"), selectedImage: UIImage(systemName: "magnifyingglass.circle")) secondViewController.tabBarItem = UITabBarItem(title: "Main", image: UIImage(systemName: "house.fill"), selectedImage: UIImage(systemName: "house")) thirdViewController.tabBarItem = UITabBarItem(title: "My", image: UIImage(systemName: "person.fill"), selectedImage: UIImage(systemName: "person")) lastViewController.tabBarItem = UITabBarItem(title: "Order", image: UIImage(systemName: "menucard.fill"), selectedImage: UIImage(systemName: "menucard")) backgroundTabBarController.viewControllers = [firstViewController, secondViewController, thirdViewController, lastViewController] backgroundTabBarController.selectedViewController = secondViewController } } // SceneDelegate import UIKit class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } window = UIWindow(windowScene: windowScene) window?.rootViewController = BackgroundViewController() window?.makeKeyAndVisible() } } // Error code Thread 1: "Could not find a storyboard named 'Main' in bundle NSBundle </Users/[MyDesktopName]/Library/Developer/CoreSimulator/Devices/[ApplicationName]/data/Containers/Bundle/Application/[ApplicationName]/BTY.app> (loaded)" But anyone of this solve the problem. How can I make UITabBarController to rootViewController? Make UITabBarController in SceneDelegate Make new UIViewController that have UITabBarController and set to rootViewController Set ViewControllers with 'UINavigationController(rootViewController:)' Present UITabBarController from other viewController
Posted
by J_ROLF.
Last updated
.