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

UIKit Documentation

Posts under UIKit tag

1,168 results found
Sort by:
Post not yet marked as solved
12 Views

XCode13 beta,iOS15. set tableview section header to 0. not working

self.tableView = [[UITableView alloc] initWithFrame:self.view.frame]; - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UILabel *label = [[UILabel alloc] init];     label.text = @"test";     return label; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {     return 0.01; } it works perfect on iOS14. but on iOS15 XCode13 beta. it doesn't work anymore. have a default header which height is 22 here
Asked
by Highmore.
Last updated
.
Post not yet marked as solved
53 Views

override var navigationItem: UINavigationItem fail in iOS 14

The following code fails since iOS14.x Is this a bug? No depreciation statements found in the SDK. Is there a workaround? import UIKit class ViewController: UIViewController { private lazy var barButtonItem: UIBarButtonItem = { UIBarButtonItem(image: .add, style: .plain, target: self, action: #selector(doSomething)) }() override var navigationItem: UINavigationItem { let item = super.navigationItem item.rightBarButtonItem = barButtonItem // <- Thread 1: EXC_BAD_ACCESS (code=2, address=...) item.title = "TestCase" return item } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } @objc private func doSomething() { print(">>doSomething") } } We are running a complex software since iOS4 and cannot simply migrate to SwiftUI. https://stackoverflow.com/questions/64270033/override-var-navigationitem-uinavigationitem-fail-in-ios-14
Asked
by pkiman.
Last updated
.
Post not yet marked as solved
87 Views

Semaphore Wait After Creating UIButton

Hi In this snippet, I've already added a button, the onDisplay action simply adds another UIButton with an addAction event to the view controller @IBAction func onDisplay(_ sender: UIButton) { let semaphore = DispatchSemaphore(value: 1)     var didComplete = false     addButton("hello world") { result in         print("result: \(result)")         didComplete = result         semaphore.signal()     }     if semaphore.wait(timeout: .now() + 5) == .timedOut {         print("timeout: \(didComplete)")     }     print("didComplete: \(didComplete)") } func addButton(_ message: String, completion: @escaping (Bool) -> Void) {     let button = UIButton(type: .system)     button.frame = CGRect(x: 100, y: 100, width: 100, height: 40)     button.backgroundColor = .systemBlue     button.setTitle(message, for: .normal)     button.titleLabel?.tintColor = .white     button.addAction(UIAction(handler: { action  in             completion(true)     }), for: .touchUpInside)     view.addSubview(button) } What I'm expecting to happen, is the new "hello world" button get created (which it does). If the user does nothing for 5 seconds (semaphore timeout), then print timeout: false. If the user tapped the button, this would print result: true in the completion closure. But what happens when I don't touch the button is didComplete: false prints out (the last line) and the semaphore.wait never gets invoked. How do I make the semaphore execute it's wait operation? Been struggling with this for days 😞
Asked
by craigaps.
Last updated
.
Post not yet marked as solved
33 Views

App Hanging with CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION

Hi, One of our users is having an issue with our iOS App hanging consistently. The trace produced is not always the same but some parts are consistent between hangs. We have not been able to reproduce on our end. One sample stack trace from user is: CrashReporter Key: bf76ea06932831ef2338cbe2b08c552b6140ef83 Hardware Model: iPhone12,3 Version: 100.0.0 Role: Foreground OS Version: iOS 14.6 App Hang: The app was terminated while unresponsive 0 libsystem_kernel.dylib ___psynch_cvwait 1 libsystem_pthread.dylib __pthread_cond_wait 2 Metal -[_MTLCommandBuffer waitUntilCompleted] 3 CoreImage CI::MetalContext::readback_bitmap(CI::Bitmap*, CI::swizzle_info) 4 CoreImage ____ZN2CI16image_get_bitmapEPNS_7ContextEPNS_5ImageE6CGRectP12CGColorSpacePNS_6BitmapEPKNS_17RenderDestinationE_block_invoke 5 CoreImage CI::recursive_tile(CI::RenderTask*, CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* ( block_pointer)(CI::ProgramNode*, CGRect)) 6 CoreImage CI::tile_node_graph(CI::Context*, CI::RenderDestination const*, char const*, CI::Node*, CGRect const&, CI::PixelFormat, CI::swizzle_info const&, CI::TileTask* ( block_pointer)(CI::ProgramNode*, CGRect)) 7 CoreImage CI::image_get_bitmap(CI::Context*, CI::Image*, CGRect, CGColorSpace*, CI::Bitmap*, CI::RenderDestination const*) 8 CoreImage -[CIContext render:toBitmap:rowBytes:bounds:format:colorSpace:] 9 CoreUI -[CUIShapeEffectStack _newFlattenedImageFromShapeCGImage:withScale:ciContext:blendOverImage:] 10 CoreUI -[CUICatalog imageByStylingImage:stylePresetName:styleConfiguration:foregroundColor:scale:] 11 UIKitCore -[UIImage _imageWithStylePresets:tintColor:traitCollection:] 12 UIKitCore -[UIImageView _renditionForSource:size:withCGImageProvider:lazy:] 13 UIKitCore -[_UIImageContentContextualEffect _renditionWithCGImageProvider:size:lazy:] 14 UIKitCore -[_UIImageContent renditionWithSize:scale:applyingEffect:] 15 UIKitCore -[_UIImageContent renditionApplyingEffect:] 16 UIKitCore -[_UIImageCGImageContent renditionApplyingEffect:] 17 UIKitCore -[_UIImageContentLayout _materializeContentsIfNeeded] 18 UIKitCore -[_UIImageContentLayout contentsMultiplyColor] 19 UIKitCore -[UIImageView _updateContentsMultiplyColorAndSwizzleFromLayout:] 20 UIKitCore -[UIImageView _setImageViewContents:] 21 UIKitCore -[UIImageView _updateState] 22 UIKitCore +[UIView(Animation) performWithoutAnimation:] 23 UIKitCore -[UIImageView _updateImageViewForOldImage:newImage:] 24 UIKitCore -[UIImageView setImage:] 25 UIKitCore -[UIButton _updateImageView] 26 UIKitCore -[UIButton layoutSubviews] 27 UIKitCore -[UIView(CALayerDelegate) layoutSublayersOfLayer:] 28 QuartzCore -[CALayer layoutSublayers] 29 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) 30 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) 31 QuartzCore CA::Context::commit_transaction(CA::Transaction*, double, double*) 32 QuartzCore CA::Transaction::commit() 33 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) 34 CoreFoundation ___CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ 35 CoreFoundation ___CFRunLoopDoObservers 36 CoreFoundation ___CFRunLoopRun 37 CoreFoundation _CFRunLoopRunSpecific 38 GraphicsServices _GSEventRunModal 39 UIKitCore -[UIApplication _run] 40 UIKitCore _UIApplicationMain 42 libdyld.dylib _start What could be causing the above? Thanks in advance for your help.
Asked Last updated
.
Post not yet marked as solved
1.4k Views

iPhone with iOS 14 beta 2 doesn't autorotate when connected to XCode debugger

I have iPhone 11 Pro running iOS 14 beta 2. In one of my projects (and only that project perhaps), the view controller doesn't autorotate when connected to XCode (11 or 12) debugger. When not connected to debugger, there is no issue in autorotation. This happens for only one particular project and it's not clear what could be blocking autorotation. None of the autorotation methods are called. I wonder what could be blocking autorotation. And if I connect any iOS 13 device, autorotation works with the debugger. Is this a known issue with iOS 14/XCode?
Asked
by Devgeek.
Last updated
.
Post not yet marked as solved
25 Views

How do I force emoji keyboard like Reminders app does?

Hi! I'm developing a new iOS app that will store user-created items. These particular items will be divided into categories, which I want to be able to assign an emoji. Just like Reminders app does for lists. In Reminders instead of choosing the icon, the user can tap on the emoji symbol and the special keyboard type will be presented. This keyboard forces the user to use emoji only and doesn't allow switching to some other languages. I wonder if it's possible for ordinary mortals? My app would benefit from using emojis this way, just like icons, then including some icons pack for users to choose from instead.
Asked
by swasta.
Last updated
.
Post not yet marked as solved
100 Views

While changing time with keypad, iOS 14 DatePicker jumps below its original position first when closed

Hi, I am trying to integrate new DatePicker available with iOS 14 in my app and I am facing an issue with its animation while closing it. Steps to reproduce: Tap on DatePicker to Select time Tap on Time textfield Use keypad to change the time Tap outside to close the picker Issue: Picker moves down slightly after closing and then jumps up to its original position
Asked
by posingh04.
Last updated
.
Post marked as solved
51 Views

navigationBar setBackgroundImage not working on iOS15

- (void)viewDidLoad {     [super viewDidLoad];     [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault]; } - (UIImage *)imageWithColor:(UIColor *)color {     CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);     UIGraphicsBeginImageContext(rect.size);     CGContextRef context = UIGraphicsGetCurrentContext();     CGContextSetFillColorWithColor(context, [color CGColor]);     CGContextFillRect(context, rect);     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();     UIGraphicsEndImageContext();     return image; } it works on iOS14, but on iOS15. it doesn't work. the color of navigationBar does't change
Asked
by Highmore.
Last updated
.
Post marked as solved
70 Views

How to set content scroll view when using SwiftUI ScrollView in UIKit view controller?

I have a UIViewController that initially does not display any scrollable content, but later on I add a child view controller that does scroll - a UIHostingController whose rootView is a GeometryReader containing a ScrollView. The problem is when you scroll the UINavigationBar remains transparent I’m sure because it couldn’t find a scroll view in the view hierarchy. There is an API to specify which scroll view to use but that’s a UIScrollView. How can I tell it about my SwiftUI scroll view? viewController.setContentScrollView(scrollView, for: .bottom)
Asked
by Jordan.
Last updated
.
Post not yet marked as solved
59 Views

Unable to enter text in programmatically created UITextField

I've created what seems to be the simplest possible programmatically-created iOS UI - just a view with a single UITextField placed in it. However, when I try to type in the text field, nothing happens - what am I missing in order to make this UI functional? My application consists of only an AppDelegate and a ViewController. My main function calls into UIApplicationMain using my AppDelegate, and I have only overridden two functions: AppDelegate's didFinishLaunchingWithOptions, and ViewController's viewDidLoad function. My AppDelegate just creates a single window, sets the root view controller, and makes it the key window: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = [[ViewController alloc] init]; [self.window makeKeyAndVisible]; return YES; } And my ViewController just creates a text field and adds it to the view: - (void)viewDidLoad { [super viewDidLoad]; // Creates a text field somewhere near-ish to the center of the screen UITextField* text = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 200, 50)]; text.borderStyle = UITextBorderStyleRoundedRect; text.returnKeyType = UIReturnKeyDone; // Set the view background as white just to make sure we're in the right place... self.view.backgroundColour = [UIColor whiteColor]; [self.view.addSubview:text]; } Some things which I have tried without any effect: Overriding loadView from ViewController as well as viewDidLoad and creating the view manually in that function Bringing the text field to the front with [self.view bringSubviewToFront:text] Setting all the enabled properties I can find - [text setUserInteractionEnabled true], [self.view setUserInteractionEnabled true], text.enabled = true Also possibly related - if I force the keyboard to become active with [text becomeFirstResponder]; immediately after adding the text field, the keyboard does show up, but no keypresses have any effect and an assert shows up in the debugger log when typing: [Assert] View <(null):0x0> does not conform to UITextInput protocol. If default text is set in the text field, I'm able to tap it to bring up the keyboard, but again run into this assert and an inactive keyboard. What am I missing in my attempt to create a simple text field programmatically in an iOS app? And, for bonus points, is there any good way to debug the assertion that fires?
Asked
by lmitchell.
Last updated
.
Post not yet marked as solved
103 Views

SwiftUI TextField inside UIViewController

Hello everyone, I'm trying to integrate a SwiftUI TextField component into a UIViewController. But any kind of tutorial I've seen, have this implementation: let childView = UIHostingController(rootView: SwiftUIView()) addChild(childView) childView.view.frame = frame view.addSubview(childView.view) childView.didMove(toParent: self) But, when I do this, my Navigation Bar disappear. But when I remove the "addChild" peace of code, everything works well. Is this a wrong thing to do? Can I remove this part of code?
Asked
by dev_agg.
Last updated
.
Post marked as solved
64 Views

Problem when using UIButton to switch view controllers in tabbed Application

Hi All, I am trying to code something that seems very simple but have not found any documentation online for my scenario. Here are the App Details: Storyboard app built using Interface Builder and a Tab Bar Controller There are 3 tabs and no Navigation Controller (No Navigation controller on purpose to make the App simple) Tab 1 = Dashboard (ViewController) Tab 2 = Air Quality Map (AirQualityMapViewController) Tab 3 = Fire Map (FireMapViewController) The issue is that I would like Users to be able to navigate to the Maps from the Dashboard when they touch different buttons on the Dashboard(disguised as an image) or use the Tabs. Segues won't work since the new screen covers the tab bar at the bottom of the screen. I am looking for a solution that does not cause the tab bar to be hidden after the User is presented the new screen. So I put the following code in the View Controller for Tab 1 (Dashboard) after the viewDidLoad method hoping it would work, but I get an error, "Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value" when the code hits the line below: Do I need to create a new class for the UITabBarController? If so how? Any advice would be appreciated as I am new to coding!!! Line where the error occurred: let tabBarController = appDelegate.window!.rootViewController as? UITabBarController Here is the full function: @IBAction func fireMapButton(_ sender: Any) { print("Fire Map Button tapped") let appDelegate = UIApplication.shared.delegate as! AppDelegate let tabBarController = appDelegate.window!.rootViewController as? UITabBarController tabBarController?.selectedIndex = 2 self.dismiss(animated: true, completion: nil) }
Asked
by kbonnet.
Last updated
.
Post not yet marked as solved
50 Views

UICollectionView reloadData only works one time in two with PDFViews in the cells

I have a UIViewController that presents a UIDocumentPicker to pick PDF files, and contains a UICollectionView that displays them (each cell contains a PDFView to do so). Here is the code: import MobileCoreServices; import PDFKit; import UIKit class ViewController: UIViewController { var urls: [URL] = [] @IBOutlet weak var collectionView: UICollectionView! @IBAction func pickFile() { DispatchQueue.main.async { let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypePDF as String], in: .import) documentPicker.delegate = self documentPicker.modalPresentationStyle = .formSheet self.present(documentPicker, animated: true, completion: nil) } } override func viewDidLoad() { collectionView.register(UINib(nibName: PDFCollectionViewCell.identifier, bundle: .main), forCellWithReuseIdentifier: PDFCollectionViewCell.identifier) } init() { super.init(nibName: "ViewController", bundle: .main) } required init?(coder: NSCoder) { fatalError() } } extension ViewController: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PDFCollectionViewCell.identifier, for: indexPath) as! PDFCollectionViewCell cell.pdfView.document = PDFDocument(url: urls[indexPath.row]) return cell } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return urls.count } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { CGSize(width: 150, height: 150) } } extension ViewController: UIDocumentPickerDelegate { // MARK: PDF Picker Delegate func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { controller.dismiss(animated: true, completion: nil) } func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { controller.dismiss(animated: true, completion: { DispatchQueue.main.async { self.urls.append(contentsOf: urls) self.collectionView.reloadData() } }) } } class PDFCollectionViewCell: UICollectionViewCell { static let identifier = "PDFCollectionViewCell" @IBOutlet weak var pdfView: PDFView! { didSet { setPdfViewUI() } } func setPdfViewUI() { pdfView.displayMode = .singlePage pdfView.autoScales = true pdfView.displayDirection = .vertical pdfView.isUserInteractionEnabled = false } } Now, for some reason, the collectionView.reloadData() actually only works one time in two. It works the first time, then the second time nothing happens, then the third time the collection view is updated again with the three expected elements... I realized that even if I'm calling reloadData(), the dataSource and delegate methods (numberOfItems/cellForItem) are not getting called when this happens. Any idea of what is happening? Am I doing something wrong? Thank you for your help!
Asked Last updated
.
Post marked as solved
71 Views

Show UIImageView for 1 second and hide again

Hello. I am trying to show an image for a short time, in an animated way, and hidden again. This is the function: @IBOutlet var statusField: UIImageView! @IBAction func debugbutton(_ sender: UIButton) { showIcon() } override func viewDidLoad() { super.viewDidLoad() statusField.isHidden = true func showIcon() { statusField.isHidden = false UIView.animate(withDuration: 1, delay: 0.5, options: UIView.AnimationOptions.transitionFlipFromTop, animations: { self.statusField.alpha = 0 }, completion: { finished in self.statusField.isHidden = true }) } When I run the function for the first time it works fine but then it stops doing it. The icon is no longer displayed. Any advice on what's going on? Thanks!
Asked Last updated
.
Post not yet marked as solved
262 Views

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.
Asked
by DropZap.
Last updated
.