What's new in UIKit

RSS for tag

Discuss the WWDC21 session What's new in UIKit.

Posts under wwdc21-10059 tag

16 Posts

Post

Replies

Boosts

Views

Activity

How do you apply a diffable data source UI snapshot only after awaiting (with async/await) data fetched from the network?
I'm new to async/await, and am currently migrating my completion handler code to Swift 5.5's concurrency features. After generating an sync alternative in Xcode to my function func fetchMatchRecords(completion: @escaping ([Match]) -> Void), it becomes func fetchMatchRecords() async -> [Match]. I'm not sure how it would be used in the context of UIKit and diffable data sources. In a viewDidLoad, previously it would be MatchHistoryController.shared.fetchMatchRecords() { matches in DispatchQueue.main.async { self.dataSource.apply(self.initialSnapshot(), animatingDifferences: false) } } But I'm not sure how it would be used now Task { await MatchHistoryController.shared.fetchMatchRecords() } self.dataSource.apply(self.initialSnapshot(), animatingDifferences: false) How would I make sure that the snapshot is applied only after awaiting a successful fetch result? Here's the definition of initialSnapshot() that I used: func initialSnapshot() -> NSDiffableDataSourceSnapshot<Section, Match> { var snapshot = NSDiffableDataSourceSnapshot<Section, Match>() snapshot.appendSections([.main]) snapshot.appendItems(MatchHistoryController.shared.matches) return snapshot }
1
0
2.2k
Sep ’23
How do I get a tab bar in iOS15 that looks like the one in iOS14?
I don't understand the changes made to the tab bar in iOS 15. In my app, I have a collection view that goes all the way down to the bottom of the screen. When the tab bar appears, it covers some of that collection view, which is fine. However, in iOS15, the tab bar has no background (and no blur effect), thus making the tab bar item text hard to see over the collection view. In interface builder, I tried turning on the "Scroll Edge" option. This gives a translucent background to the tab bar similar to what I had in iOS 14. Unfortunately, the menu tab bar item text size is affected by this option. For some reason, it doesn't use the font size I set, but something smaller. Why is this happening? How do I get it to use the correct font size? P.S. I'm only using text for the tab bar items. There are no images.
11
0
16k
Feb ’22
maximumContentSizeCategory vs. UITableView
The new UIView properties maximumContentSizeCategory and minimumContentSizeCategory sound really useful. But I’m finding the following odd behaviors and am not sure whether these are bugs or features: Setting these properties on a scene's root UIWindow has no effect. The WWDC video says it applies “to view hierarchies” but it seems you actually need to set these directly on each view controller’s root view individually. Maybe that’s by design to prevent “abuse” without requiring a bit of extra work. If you set them on a UITableView the result is inconsistent. It affects cell content correctly, but section headers and footers don’t respect the setting, giving a weird result where the headers and footers can be larger than the cells. I would expect it to affect the table’s entire view hierarchy (cells, headers, and footers) in order to give a coherent appearance. I’m seeing these behaviors on all iOS 15 releases including the current 15.4 beta 2.
0
0
876
Feb ’22
How does the new UIResponderStandardEditActions.pasteAndGo(_:) work?
In iOS 15, the following actions have been added to UIResponderStandardEditActions: - (void)pasteAndMatchStyle:(nullable id)sender API_AVAILABLE(ios(15.0)); - (void)pasteAndGo:(nullable id)sender API_AVAILABLE(ios(15.0)); - (void)pasteAndSearch:(nullable id)sender API_AVAILABLE(ios(15.0)); In https://developer.apple.com/wwdc21/10059 it is explained that these additional actions are specifically meant to avoid the "Copy & Paste Banner" that notifies the user that the app accessed the pasteboard. Since these are user initiated actions, the OS now knows that the intent was to paste so there is no need to notify the user. However, I cannot get this to work. I tried to do the following: class ViewController: UIViewController { @IBOutlet weak var textField: UITextField! override func viewDidLoad() { super.viewDidLoad() let item = UIMenuItem(title: "Paste & Go", action: #selector(pasteAndGo(_:))) UIMenuController.shared.menuItems = [item] } override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { if action == #selector(pasteAndGo(_:)) { return true } return super.canPerformAction(action, withSender: sender) } override func pasteAndGo(_ sender: Any?) { textField.pasteAndGo(sender) } } Basically, I add it as a custom item to the UIMenuController, announce that I can handle pasteAndGo(_:) and then delegate it to the UITextField when the menu item is selected. The menu item shows up, but when selected, it causes an exception telling me that UITextField does not respond to the pasteAndGo: selector: Thread 1: "-[UITextField pasteAndGo:]: unrecognized selector sent to instance 0x14d813800" I don't understand this part. Isn't pasteAndGo(_:) supposed to be aliased to paste(_:) inside the UITextField? I thought that since these are aliases, we can get the same behaviour (text is pasted) but now we know in our actions what the actual intent was so that we can act on that accordingly. I've tried to set the keyboard type to "Web Search" and the Return Key to "Go" but that also made no difference. Has anyone made this work? I'm starting to think that this may not have actually shipped in iOS 15.
1
0
1.4k
Jan ’22
Reference to member 'delegate' cannot be resolved without a contextual type
Im not sure why, but my tableView.delegate & tableView.data are returning errors "Reference to member 'delegate' cannot be resolved without a contextual type" "Reference to member 'dataSource' cannot be resolved without a contextual type" I've done everything around my code to see why I am getting these errors but I do not understand. My code is below import UIKit @MainActor class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var TableView: UITableView! public var meals = [Meal]() override func viewDidLoad() { super.viewDidLoad() fetchJSON { print("APICompleted") } tableView.delegate = self //error// tableView.dataSource = self //error// } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return meals.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell(style: .subtitle , reuseIdentifier: nil) cell.textLabel?.text = meals[indexPath.row].strMeal.capitalized return cell } func fetchJSON(completed: @escaping () -> ()) { let jsonUrlString = "https://www.themealdb.com/api/json/v1/1/filter.php?c=Beef" guard let url = URL(string: jsonUrlString) else { print("invalid url string lel") return } print("Select a meal to make today!") URLSession.shared.dataTask(with: url) { data, response, error in guard let data = data else { return } do { let decoder = JSONDecoder() let mealDetailResponse = try decoder.decode(MealDetailResponse.self, from: data) for meal in mealDetailResponse.meals { print("The Meal is \(meal)") DispatchQueue.main.async { completed() } } }catch { print(error) } }.resume() } }
3
0
5.0k
Nov ’21
iOS15 NavigationBar background
Hi,I set My navigationBar like this in viewWillApper appearance.configureWithOpaqueBackground() appearance.backgroundColor = <your tint color> navigationBar.standardAppearance = appearance; navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance UINavigationBar.isTranslucent = false The page behaves normally when it first appears, inwiewWilDisappear,I set another style for the next page that will appear When the page returns from another controller by dismissViewControllerAnimated:completion The background of the navigation bar will first appear transparent and then display the correct background but works fine on iOS14
1
0
3.7k
Oct ’21
Swift, iOS15, UIKit, CollectionView header issue
I am testing iOS15 and some new functionalities of UIKit. I've encountered some issues, not sure how to solve them. I did not change that code. This is just a piece of code that worked perfectly with the iOS 14, now after updating my target, it throws an error. Xcode crashes the moment when my custom header for the UICollectionView of type UICollectionElementKindSectionHeader is being returned for the dataSource. Here is my code: private func configureDataSource() { dataSource = UICollectionViewDiffableDataSource<Section, Follower>(collectionView: collectionView, cellProvider: { (collectionView, indexPath, followers) -> UICollectionViewCell? in let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FollowerCell.reuseId, for: indexPath) as! FollowerCell cell.set(on: followers) return cell }) dataSource.supplementaryViewProvider = { (collectionView, kind, indexPath) in let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: FollowersCollectionHeaderView.reuseId, for: indexPath) as! FollowersCollectionHeaderView header.set(with: self.user) return header } } The log says: the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view of element kind 'FollowersCollectionHeaderView' the data source dequeued a view registered for the element kind 'UICollectionElementKindSectionHeader'. I did cast UICollectionElementKindSectionHeader to FollowersCollectionHeaderView, therefore I am not sure what is the issue here. I've watched WWDC21 what's new in UIKit but haven't seen any mentioning of any change for that particular code. Any suggestions, what to fix in that code?
11
0
9.5k
Oct ’21
How to disable keyboard input for UIDatePicker with preferredDatePickerStyle set to .wheels on iOS 15
Currently in Xcode 13 beta 5, if I have a UIDatePicker with the following configuration: let datePicker = UIDatePicker() datePicker.preferredDatePickerStyle = .wheels datePicker.datePickerMode = .dateAndTime the user can tap the highlighted date or time to bring up the keyboard. This effectively "breaks" a UI (which worked fine pre-iOS 15) in which the date picker is anchored to the bottom of the screen, as the keyboard then covers the entirety of the date picker. Is there a way to disable keyboard input for a date picker with the wheels style?
1
0
4.4k
Sep ’21
How to change tab bar item text color programmatically in iOS 15? It doesn't work like in iOS 14.
If you try to change the bar item text color programmatically like in iOS 14, it doesn't work in iOS 15. For example: // https://stackoverflow.com/questions/2576592/changing-font-size-of-tabbaritem/ UITabBarItem.appearance().setTitleTextAttributes(   [NSAttributedString.Key.foregroundColor: UIColor.red],   for: .normal) This correctly changes the color when the tab bar is on top of a scroll view. However, when the tab bar background becomes clear, all tab bar item text is red and not just the text for the currently selected tab. Is this a bug in iOS 15? Or is this code wrong for iOS 15?
2
0
11k
Sep ’21
Arrow Buttons cause UIScrollView to scroll after being held down
I have been testing out an existing app with the new Apple TV 4K (2nd generation) - the one with the new remote - and there seems to be a new behavior implemented with this new remote. If you have focusable content (let's say a custom list) in a UIScrollView, and the user presses and holds one of the up/down/left/right buttons around the touch-pad, the focus engine will start by moving focus in the direction of the arrow button being held down - one-by-one, as expected, however, after a certain amount of time, the focus is removed and the view simply starts slowly scrolling and no more focus events are called. Is there a way to prevent this behavior from happening, and simply have arrow buttons move focus (even after being held down)? How do I know that the UIScrollView has entered into this special state of auto-scrolling while the arrow button is held down? None of the UIScrollViewDelegate methods seem to cover this use-case. I have tried disabling the panGestureRecognizer associated with the UIScrollView but that doesn't work. I am not sure how to implement this new type of UIScrollView - I was never expecting focus to be removed without the next item receiving focus.
0
0
1.2k
Jul ’21
How do you apply a diffable data source UI snapshot only after awaiting (with async/await) data fetched from the network?
I'm new to async/await, and am currently migrating my completion handler code to Swift 5.5's concurrency features. After generating an sync alternative in Xcode to my function func fetchMatchRecords(completion: @escaping ([Match]) -> Void), it becomes func fetchMatchRecords() async -> [Match]. I'm not sure how it would be used in the context of UIKit and diffable data sources. In a viewDidLoad, previously it would be MatchHistoryController.shared.fetchMatchRecords() { matches in DispatchQueue.main.async { self.dataSource.apply(self.initialSnapshot(), animatingDifferences: false) } } But I'm not sure how it would be used now Task { await MatchHistoryController.shared.fetchMatchRecords() } self.dataSource.apply(self.initialSnapshot(), animatingDifferences: false) How would I make sure that the snapshot is applied only after awaiting a successful fetch result? Here's the definition of initialSnapshot() that I used: func initialSnapshot() -> NSDiffableDataSourceSnapshot<Section, Match> { var snapshot = NSDiffableDataSourceSnapshot<Section, Match>() snapshot.appendSections([.main]) snapshot.appendItems(MatchHistoryController.shared.matches) return snapshot }
Replies
1
Boosts
0
Views
2.2k
Activity
Sep ’23
Input Box
We found that it can't obtain the content of input box in iOS15. When will fix this bug?
Replies
1
Boosts
0
Views
1.2k
Activity
Mar ’22
How do I get a tab bar in iOS15 that looks like the one in iOS14?
I don't understand the changes made to the tab bar in iOS 15. In my app, I have a collection view that goes all the way down to the bottom of the screen. When the tab bar appears, it covers some of that collection view, which is fine. However, in iOS15, the tab bar has no background (and no blur effect), thus making the tab bar item text hard to see over the collection view. In interface builder, I tried turning on the "Scroll Edge" option. This gives a translucent background to the tab bar similar to what I had in iOS 14. Unfortunately, the menu tab bar item text size is affected by this option. For some reason, it doesn't use the font size I set, but something smaller. Why is this happening? How do I get it to use the correct font size? P.S. I'm only using text for the tab bar items. There are no images.
Replies
11
Boosts
0
Views
16k
Activity
Feb ’22
maximumContentSizeCategory vs. UITableView
The new UIView properties maximumContentSizeCategory and minimumContentSizeCategory sound really useful. But I’m finding the following odd behaviors and am not sure whether these are bugs or features: Setting these properties on a scene's root UIWindow has no effect. The WWDC video says it applies “to view hierarchies” but it seems you actually need to set these directly on each view controller’s root view individually. Maybe that’s by design to prevent “abuse” without requiring a bit of extra work. If you set them on a UITableView the result is inconsistent. It affects cell content correctly, but section headers and footers don’t respect the setting, giving a weird result where the headers and footers can be larger than the cells. I would expect it to affect the table’s entire view hierarchy (cells, headers, and footers) in order to give a coherent appearance. I’m seeing these behaviors on all iOS 15 releases including the current 15.4 beta 2.
Replies
0
Boosts
0
Views
876
Activity
Feb ’22
How to access
How can we acesss UIKit viewcontroller component such as a button from another viewcontroller
Replies
2
Boosts
0
Views
959
Activity
Jan ’22
AppDelegate is not called
Have you encountered a situation after main is called, but AppDelegate is not called? Only a few users will encounter this situation, and it is concentrated in iOS15, and [NSProcessInfo processInfo].environment does not include 'ActivePrewarm' .
Replies
0
Boosts
0
Views
1.3k
Activity
Jan ’22
How does the new UIResponderStandardEditActions.pasteAndGo(_:) work?
In iOS 15, the following actions have been added to UIResponderStandardEditActions: - (void)pasteAndMatchStyle:(nullable id)sender API_AVAILABLE(ios(15.0)); - (void)pasteAndGo:(nullable id)sender API_AVAILABLE(ios(15.0)); - (void)pasteAndSearch:(nullable id)sender API_AVAILABLE(ios(15.0)); In https://developer.apple.com/wwdc21/10059 it is explained that these additional actions are specifically meant to avoid the "Copy & Paste Banner" that notifies the user that the app accessed the pasteboard. Since these are user initiated actions, the OS now knows that the intent was to paste so there is no need to notify the user. However, I cannot get this to work. I tried to do the following: class ViewController: UIViewController { @IBOutlet weak var textField: UITextField! override func viewDidLoad() { super.viewDidLoad() let item = UIMenuItem(title: "Paste & Go", action: #selector(pasteAndGo(_:))) UIMenuController.shared.menuItems = [item] } override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool { if action == #selector(pasteAndGo(_:)) { return true } return super.canPerformAction(action, withSender: sender) } override func pasteAndGo(_ sender: Any?) { textField.pasteAndGo(sender) } } Basically, I add it as a custom item to the UIMenuController, announce that I can handle pasteAndGo(_:) and then delegate it to the UITextField when the menu item is selected. The menu item shows up, but when selected, it causes an exception telling me that UITextField does not respond to the pasteAndGo: selector: Thread 1: "-[UITextField pasteAndGo:]: unrecognized selector sent to instance 0x14d813800" I don't understand this part. Isn't pasteAndGo(_:) supposed to be aliased to paste(_:) inside the UITextField? I thought that since these are aliases, we can get the same behaviour (text is pasted) but now we know in our actions what the actual intent was so that we can act on that accordingly. I've tried to set the keyboard type to "Web Search" and the Return Key to "Go" but that also made no difference. Has anyone made this work? I'm starting to think that this may not have actually shipped in iOS 15.
Replies
1
Boosts
0
Views
1.4k
Activity
Jan ’22
Reference to member 'delegate' cannot be resolved without a contextual type
Im not sure why, but my tableView.delegate & tableView.data are returning errors "Reference to member 'delegate' cannot be resolved without a contextual type" "Reference to member 'dataSource' cannot be resolved without a contextual type" I've done everything around my code to see why I am getting these errors but I do not understand. My code is below import UIKit @MainActor class HomeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var TableView: UITableView! public var meals = [Meal]() override func viewDidLoad() { super.viewDidLoad() fetchJSON { print("APICompleted") } tableView.delegate = self //error// tableView.dataSource = self //error// } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return meals.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = UITableViewCell(style: .subtitle , reuseIdentifier: nil) cell.textLabel?.text = meals[indexPath.row].strMeal.capitalized return cell } func fetchJSON(completed: @escaping () -> ()) { let jsonUrlString = "https://www.themealdb.com/api/json/v1/1/filter.php?c=Beef" guard let url = URL(string: jsonUrlString) else { print("invalid url string lel") return } print("Select a meal to make today!") URLSession.shared.dataTask(with: url) { data, response, error in guard let data = data else { return } do { let decoder = JSONDecoder() let mealDetailResponse = try decoder.decode(MealDetailResponse.self, from: data) for meal in mealDetailResponse.meals { print("The Meal is \(meal)") DispatchQueue.main.async { completed() } } }catch { print(error) } }.resume() } }
Replies
3
Boosts
0
Views
5.0k
Activity
Nov ’21
setContentOffset:animated: has no animation effect on iPhone13
When I use UICollectionView on iPhone13 and the latest devices, [collectionView setContentOffset:CGPointMake(100, 0) animated:YES] will cause caton. animated:YES has no animation effect, but this method works well on other devices, They are IOS 15.0.2 systems
Replies
0
Boosts
0
Views
531
Activity
Oct ’21
iOS15 NavigationBar background
Hi,I set My navigationBar like this in viewWillApper appearance.configureWithOpaqueBackground() appearance.backgroundColor = <your tint color> navigationBar.standardAppearance = appearance; navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance UINavigationBar.isTranslucent = false The page behaves normally when it first appears, inwiewWilDisappear,I set another style for the next page that will appear When the page returns from another controller by dismissViewControllerAnimated:completion The background of the navigation bar will first appear transparent and then display the correct background but works fine on iOS14
Replies
1
Boosts
0
Views
3.7k
Activity
Oct ’21
ios14.6 The code for rotating the screen does not take effect
[UIDevice.currentDevice setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
Replies
1
Boosts
0
Views
921
Activity
Oct ’21
Swift, iOS15, UIKit, CollectionView header issue
I am testing iOS15 and some new functionalities of UIKit. I've encountered some issues, not sure how to solve them. I did not change that code. This is just a piece of code that worked perfectly with the iOS 14, now after updating my target, it throws an error. Xcode crashes the moment when my custom header for the UICollectionView of type UICollectionElementKindSectionHeader is being returned for the dataSource. Here is my code: private func configureDataSource() { dataSource = UICollectionViewDiffableDataSource<Section, Follower>(collectionView: collectionView, cellProvider: { (collectionView, indexPath, followers) -> UICollectionViewCell? in let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FollowerCell.reuseId, for: indexPath) as! FollowerCell cell.set(on: followers) return cell }) dataSource.supplementaryViewProvider = { (collectionView, kind, indexPath) in let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: FollowersCollectionHeaderView.reuseId, for: indexPath) as! FollowersCollectionHeaderView header.set(with: self.user) return header } } The log says: the view returned from -collectionView:viewForSupplementaryElementOfKind:atIndexPath: does not match the element kind it is being used for. When asked for a view of element kind 'FollowersCollectionHeaderView' the data source dequeued a view registered for the element kind 'UICollectionElementKindSectionHeader'. I did cast UICollectionElementKindSectionHeader to FollowersCollectionHeaderView, therefore I am not sure what is the issue here. I've watched WWDC21 what's new in UIKit but haven't seen any mentioning of any change for that particular code. Any suggestions, what to fix in that code?
Replies
11
Boosts
0
Views
9.5k
Activity
Oct ’21
How to disable keyboard input for UIDatePicker with preferredDatePickerStyle set to .wheels on iOS 15
Currently in Xcode 13 beta 5, if I have a UIDatePicker with the following configuration: let datePicker = UIDatePicker() datePicker.preferredDatePickerStyle = .wheels datePicker.datePickerMode = .dateAndTime the user can tap the highlighted date or time to bring up the keyboard. This effectively "breaks" a UI (which worked fine pre-iOS 15) in which the date picker is anchored to the bottom of the screen, as the keyboard then covers the entirety of the date picker. Is there a way to disable keyboard input for a date picker with the wheels style?
Replies
1
Boosts
0
Views
4.4k
Activity
Sep ’21
How to change tab bar item text color programmatically in iOS 15? It doesn't work like in iOS 14.
If you try to change the bar item text color programmatically like in iOS 14, it doesn't work in iOS 15. For example: // https://stackoverflow.com/questions/2576592/changing-font-size-of-tabbaritem/ UITabBarItem.appearance().setTitleTextAttributes(   [NSAttributedString.Key.foregroundColor: UIColor.red],   for: .normal) This correctly changes the color when the tab bar is on top of a scroll view. However, when the tab bar background becomes clear, all tab bar item text is red and not just the text for the currently selected tab. Is this a bug in iOS 15? Or is this code wrong for iOS 15?
Replies
2
Boosts
0
Views
11k
Activity
Sep ’21
UIProgressView on iOS 15 beta 2
UIProgressView built on Xcode 12.4 shows a little bit of progress on iOS 15 beta 2 in spite of 0.0 progress. Is it a bug or a new behavior?
Replies
2
Boosts
0
Views
1.4k
Activity
Jul ’21
Arrow Buttons cause UIScrollView to scroll after being held down
I have been testing out an existing app with the new Apple TV 4K (2nd generation) - the one with the new remote - and there seems to be a new behavior implemented with this new remote. If you have focusable content (let's say a custom list) in a UIScrollView, and the user presses and holds one of the up/down/left/right buttons around the touch-pad, the focus engine will start by moving focus in the direction of the arrow button being held down - one-by-one, as expected, however, after a certain amount of time, the focus is removed and the view simply starts slowly scrolling and no more focus events are called. Is there a way to prevent this behavior from happening, and simply have arrow buttons move focus (even after being held down)? How do I know that the UIScrollView has entered into this special state of auto-scrolling while the arrow button is held down? None of the UIScrollViewDelegate methods seem to cover this use-case. I have tried disabling the panGestureRecognizer associated with the UIScrollView but that doesn't work. I am not sure how to implement this new type of UIScrollView - I was never expecting focus to be removed without the next item receiving focus.
Replies
0
Boosts
0
Views
1.2k
Activity
Jul ’21