What's new in UIKit

RSS for tag

Discuss the WWDC21 session What's new in UIKit.

View Session

Posts under wwdc21-10059 tag

14 Posts
Sort by:
Post not yet marked as solved
0 Replies
187 Views
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.
Posted
by
Post not yet marked as solved
2 Replies
219 Views
How can we acesss UIKit viewcontroller component such as a button from another viewcontroller
Posted
by
Post not yet marked as solved
0 Replies
370 Views
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' .
Posted
by
Post not yet marked as solved
0 Replies
358 Views
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.
Posted
by
Post not yet marked as solved
3 Replies
1.3k Views
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() } }
Posted
by
Post not yet marked as solved
0 Replies
251 Views
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
Posted
by
Post not yet marked as solved
0 Replies
468 Views
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 }
Posted
by
Post not yet marked as solved
1 Replies
1.6k Views
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?
Posted
by
Post not yet marked as solved
1 Replies
2.7k Views
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
Posted
by
Post marked as Apple Recommended
4.3k Views
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?
Posted
by
Post not yet marked as solved
2 Replies
5.0k Views
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?
Posted
by
Post not yet marked as solved
10 Replies
9.9k Views
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.
Posted
by