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

UIKit Documentation

Posts under UIKit tag

1,018 results found
Sort by:
Post marked as solved
29k Views

Launching iOS app from iCloud Drive

My iOS app supports a document type and includes the appropriate UTI data. It can therefore open documents of a specific type from mail attachments, for instance. It works well.I am currently stumped, however: when I open a document from the iCloud Drive app (tap document, share button, "Copy to <app>") my application gets launched but any attempts to copy the item from the provided URL fails with NSCocoaErrorDomain, error 257 (basically telling me I don't have the permissions to read the file). This issue is not present when my app is running in the background, however, and does not seem to occur when the app gets launched from a mail attachment (whether it's running ot not).I compared the URLs handed to my app and they are identical, whether the app was running or not.Here's the URL my app is handed: "file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/filename.ext"The code I'm using is the following:// uniqueURL is a destination URL in my app's sandbox: // file:///var/mobile/Containers/Data/Application/12AB2BA0-EA63-4FAC-A7D8-779964868B06/Documents/filename.ext dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { let fileCoordinator = NSFileCoordinator(filePresenter: nil) fileCoordinator.coordinateReadingItemAtURL(url, options: .WithoutChanges, error: nil) { newURL in do { try NSFileManager.defaultManager().copyItemAtURL(newURL, toURL: uniqueURL) } catch { print("Error!") // this is where I'm getting NSCocoaErrorDomain:257 } }This issue seems to be identical to that other thread:https://forums.developer.apple.com/message/29985#29985However, I'm not running on a beta OS. My device is an iPhone 6s running iOS 9.3.2 (13F69).
Asked
by bbousquet.
Last updated
.
Post not yet marked as solved
4.3k Views

iOS 15 CollectionView Crash (Xcode 13)

On iOS 15 builds created with Xcode 13, a collectionView is crashing when collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .top) is called and it has no items in its datasource yet. Crash Message: Attempted to scroll the collection view to an out-of-bounds section (0) when there are only 0 sections. Note This does not happen on any builds created by versions of Xcode before Xcode 13. Is this an expected change or something that needs to be addressed?
Asked Last updated
.
Post not yet marked as solved
160 Views

Screenshot restriction in iOS Native

i have a requirement where we need to restrict the user in taking the screen shot. as of now iam using this code  NotificationCenter.default.addObserver(self, selector: #selector(didDetectScreenshot), name: UIApplication.userDidTakeScreenshotNotification, object: nil) This is triggered after taking the screenshot. Is there any possibility to completely restrict in taking the screenshot.
Asked Last updated
.
Post not yet marked as solved
21 Views

Layout Error

I got this error message and my App is killed. Fatal Exception: NSRangeException *** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2] I developed using UITableViewCell API. When calling UITableViewCell API, CollectionViewLeftAlignFlowLayout is reproduced every time. Has anyone experienced this? What was the cause?
Asked
by Eunyoung.
Last updated
.
Post not yet marked as solved
18 Views

Redirecting focus to the UICollectionView header

Hello. I have an interactive component based on UISegmentedControl that is displayed in the top header of a UICollectionView laid out using UICollectionViewCompositionalLayout. The UICollectionView is displayed within a container UIViewController. That container has call to action buttons. When the focus is on one of these buttons and the user swipes down on the remote, I would like the focus to be redirected to the top header. Where should I place the UIFocusGuide ? I have tried adding it to the container UIViewController at the same level as the buttons and UICollectionView (in between) to no avail.
Asked
by shindo.
Last updated
.
Post not yet marked as solved
10k Views

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?
Asked
by xinatanil.
Last updated
.
Post marked as solved
4.7k Views

How to make USSD call on iOS 15.4 beta

My App try to call via tel: scheme for USSD, it worked on iOS 15.3 and earlier but doesn't work on iOS 15.4 beta. let number = "10*10#" // Doesn't work. // let number = "1234" // This is Okay. guard let url = URL(string: "tel:" + number),           UIApplication.shared.canOpenURL(url) else { fatalError() } UIApplication.shared.open(url, options: [:]) { success in print("success: \(success)") // This is true } canOpenUrl() returns true, which means now we can call open() method. But nothing happens when we call open(url: options: completion:).
Asked
by user21.
Last updated
.
Post not yet marked as solved
39 Views

CLLocationButton does not show pressed states

I am starting to use CLLocationButton in my apps, but can see an issue with its behavior. When the user taps on a UIButton it is visually noticeable that it's being tapped. Color/Alpha change, image adjusts, etc... When the user taps on a CLLocationButton there is no queues as to it being pressed. I've had several test users complain already that they think the button is not working given that the action might not result in an immediately change to the UI. Apple FB: FB10019792 Open Radar: https://openradar.appspot.com/FB10019792
Asked
by hotngui.
Last updated
.
Post not yet marked as solved
1.5k Views

FBSSceneSnapshotErrorDomain Code=4

[Common] Error response from snapshot request action of type 1 gave Error Domain=FBSSceneSnapshotErrorDomain Code=4 "an error occurred during a scene snapshotting operation" UserInfo={NSLocalizedDescription=an error occurred during a scene snapshotting operation, NSLocalizedFailureReason=an unrelated condition or state was not satisfied}
Asked
by fruit_zzr.
Last updated
.
Post not yet marked as solved
283 Views

userDidTakeScreenshotNotification not working on macOS

Currently testing our app's viability for running on native Apple Silicon and we're noticing that UIApplication.userDidTakeScreenshotNotification is not being invoked when taking a screenshot. NotificationCenter.default.addObserver(self, selector: #selector(screenshotTaken), name: UIApplication.userDidTakeScreenshotNotification, object: nil) Is there another API I should be using, or is this feature just not possible running on a mac?
Asked Last updated
.
Post not yet marked as solved
45 Views

UIVisualEffectContentView.contentView.addSubview not working in Swift Playground

UIVisualEffectContentView.contentView.addSubview appears to be actually trying to add the sub view to the parent UIVisualEffectView in Swift Playgrounds. Code that works fine in an actual iOS app causes Swift Playgrounds to produce error: "Do not add subviews directly to the visual effect view itself, instead add them to the -contentView." Except that is exactly what the code is doing "blur.contentView.addSubview(vib)" So the internal implementation in Swift Playgrounds must be doing something wrong. Again the same code works fine in an iOS app.
Asked Last updated
.
Post not yet marked as solved
26 Views

Incorrect Content Size in UITableView grouped style

HI, ContentSize is incorrect in UITableView grouped style in iOS15.4, I run this below code in iOS 15.4 using Xcode 13.1 which has the content size 40 (cell 0 height + cell 1 height), and it works fine. But in the Xcode 13.3.1 content size is approximately 60. class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {       lazy var tableView: UITableView = {     let tableView = UITableView(frame: .zero, style: .grouped)     tableView.backgroundColor = UIColor.lightGray     tableView.sectionHeaderTopPadding = 0.01     tableView.delegate = self     tableView.dataSource = self     tableView.translatesAutoresizingMaskIntoConstraints = false     tableView.register(TableViewCell.self, forCellReuseIdentifier: "TableViewCell")     return tableView   }()   override func viewDidLoad() {     super.viewDidLoad()           self.view.addSubview(tableView)           tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true     tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true     tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true     tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true   }           //MARK: UITableViewDataSource & UITableViewDelegate   func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {     return 2   }       func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {     let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell") as! TableViewCell           return cell   }   func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {     return 20   }       func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {     return nil   }       func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {     return CGFloat.leastNormalMagnitude   }       func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {     return nil   }       func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {     return CGFloat.leastNormalMagnitude   }     } class TableViewCell: UITableViewCell {       override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {     super.init(style: style, reuseIdentifier: reuseIdentifier)     self.backgroundColor = .red   }       required init?(coder: NSCoder) {     fatalError("init(coder:) has not been implemented")   } }
Asked
by Jk398.
Last updated
.
Post not yet marked as solved
2.9k Views

What causes this error? [UIFocus] Failed to update focus with context

I have an app that just started becoming unresponsive. I just updated my Mac to 12.3 and Xcode to 13.3. When compiling my iOS app for iPhone and iPad, it deploys just fine to devices. But, when running in the Simulator the UI stops functioning after a few renders. No input seems to be received, no renders are happening. In the log I see this message: [UIFocus] Failed to update focus with context <UIFocusUpdateContext: 0x60000081a8a0: previouslyFocusedItem=(null), nextFocusedItem=(null), focusHeading=None>. No additional info available. What is causing this only for the Simulator? (I saw another thread with similar-looking questions.) I even created a completely new Xcode Project, and though the UI is still responsive, in the logs I see: [UIFocus] Failed to update focus with context <UIFocusUpdateContext: 0x6000025aa940: previouslyFocusedItem=(null), nextFocusedItem=(null), focusHeading=None>. No additional info available. [UIFocus] Deferring focus update to item <SwiftUI.ListTableViewCell: 0x7fd632846a00>. No additional info available. [UIFocus] Failed to update focus with context <UIFocusUpdateContext: 0x6000025a5fe0: previouslyFocusedItem=(null), nextFocusedItem=(null), focusHeading=None>. No additional info available. [UIFocus] Deferring focus update to item <SwiftUI.ListTableViewCell: 0x7fd63284ca00>. No additional This feels like a relatively new error I haven't seen before.
Asked Last updated
.
Post marked as solved
1.2k Views

What's the best way to create a fully dynamic UIMenu for a UIButton or UIBarButtonItem?

I've got a UIBarButtonItem in my app that currently presents an action sheet of items. I want to switch this to a UIMenu with iOS 14's new APIs for buttons and bar button items. But somme of the contents of the action sheet change based on the state of the view controller when the action sheet is triggered. With the action sheet, I generate a different action sheet every time the bar button item's target action is called. But with the new APIs, I have to generate the menu ahead of time and assign it to the button. What's the best way to get the menu to update every time it's presented? I tried UIDeferredMenuElement, but it caches the result of its provider. Feedback FB7824467 suggests adding a property to UIDeferredMenuElement to disable the caching of the provider result.
Asked Last updated
.