Post

Replies

Boosts

Views

Activity

Reply to CAGradientLayer covers Label in Table View Cell
I changed as floors, and it works here. layer must be added to cell.contentView. I set the layer in cellForRowAt func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "CellItem2", for: indexPath) let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) if filtered { cell.textLabel?.text = filteredData[indexPath.row] } else { cell.textLabel?.text = collectionEintraege[indexPath.row] } let layer = CAGradientLayer() layer.frame = cell.bounds.insetBy(dx: 4, dy: 4) // CGRect(x: 0, y: 0, width: 500, height: 40)         layer.colors = [UIColor(red: 0.19, green: 0.22, blue: 0.25, alpha: 1.00).cgColor, UIColor(red: 0.25, green: 0.26, blue: 0.28, alpha: 1.00).cgColor] layer.borderWidth = 1 layer.borderColor = UIColor.white.cgColor cell.contentView.layer.addSublayer(layer) // -- That's the key cell.textLabel?.textColor = UIColor.white cell.textLabel?.font = UIFont(name: "Helvetica", size: 25.0) return cell }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Custom NSView crashes app but runs fine in Xcode
I did some more test, to check how to use topLevelObjects. I replaced IBOutlets by simple properties. It works well in Xcode, but crashes the same in Finder. But I do think that's the direction to look at. final class KaraokeSongView: NSView { var rootView: NSView! var songTitleView: NSTextField! var currentTimeView: NSTextField! var songLengthView: NSTextField! var songPositionView: NSProgressIndicator! var playPauseButton: NSButton! var dragDestination: KaraokeSongDragDestinationView! var unpackProgress: NSProgressIndicator! var showInFinder: NSButton! var songDisplayView: NSImageView! var songVideoView: AVPlayerView! var volumeSlider: NSSlider! var songUrl: URL! var player = AVAudioPlayer() var avPlayer = AVPlayer() let formatter = DateComponentsFormatter() var currentCdgPacket = 1.0 var timer: Timer! var myArray : NSArray? required init?(coder: NSCoder) { super.init(coder: coder) let myName = type(of: self).className().components(separatedBy: ".").last! if let nib = NSNib(nibNamed: myName, bundle: Bundle(for: type(of: self))) { nib.instantiate(withOwner: self, topLevelObjects: &myArray) // nil) print("myArray count", myArray?.count) print("myArray[0]", myArray![0]) print("myArray[1]", myArray![1]) if let topView = myArray![0] as? NSView { print("topView 0", topView, topView.frame) for newView in topView.subviews { self.addSubview(newView) print("newView", type(of: newView), newView.frame) } } else if let topView = myArray![1] as? NSView { print("topView 1", topView, topView.frame) for newView in topView.subviews { self.addSubview(newView) print("newView", type(of: newView), newView.frame) } } // setup() } else { print("init couldn't load nib") } } myArray contains 2 objects: NSApplication and the top NSView But in any order, hence the need to test [0] and [1]. Here the output, showing we get all the objects. And some errors at the beginning. We should now need to connect to properties in the class. 2021-03-14 17:09:02.287271+0100 BugCode[50871:3973074] CDN - client insert callback function client = 0 type = 17 function = 0x7fff322a4246 local_olny = false 2021-03-14 17:09:02.287323+0100 BugCode[50871:3973074] CDN - client setup_remote_port 2021-03-14 17:09:02.287352+0100 BugCode[50871:3973074] CDN - Bootstrap Port: 1799 2021-03-14 17:09:02.287502+0100 BugCode[50871:3973074] CDN - Remote Port: 41999 (com.apple.CoreDisplay.Notification) 2021-03-14 17:09:02.287545+0100 BugCode[50871:3973074] CDN - client setup_local_port 2021-03-14 17:09:02.287567+0100 BugCode[50871:3973074] CDN - Local Port: 24579 2021-03-14 17:09:02.292836+0100 BugCode[50871:3973128] [plugin] AddInstanceForFactory: No factory registered for id CFUUID 0x60000023f9c0 F8BB1C28-BAE8-11D6-9C31-00039315CD46 myArray count Optional(2) myArray[0] NSView: 0x100625a90 myArray[1] NSApplication: 0x6000035000b0 topView 0 NSView: 0x100625a90 (0.0, 0.0, 490.0, 340.0) newView NSSlider (448.0, 27.0, 24.0, 255.0) newView AVPlayerView (0.0, 0.0, 432.0, 280.0) newView NSImageView (0.0, 0.0, 432.0, 280.0) newView NSTextField (431.0, 292.0, 41.0, 16.0) newView NSTextField (18.0, 316.0, 416.0, 16.0) newView NSProgressIndicator (53.0, 289.0, 372.0, 20.0) newView NSButton (440.0, 0.0, 40.0, 25.0) newView NSBox (5.0, 286.0, 465.0, 5.0) newView NSTextField (6.0, 291.0, 41.0, 16.0) newView KaraokeSongDragDestinationView (0.0, 0.0, 490.0, 340.0) newView NSButton (438.0, 306.0, 49.0, 32.0) myArray count Optional(2) myArray[0] NSApplication: 0x6000035000b0 myArray[1] NSView: 0x10062b660 topView 1 NSView: 0x10062b660 (0.0, 0.0, 490.0, 340.0) newView NSSlider (448.0, 27.0, 24.0, 255.0) newView AVPlayerView (0.0, 0.0, 432.0, 280.0) newView NSImageView (0.0, 0.0, 432.0, 280.0) newView NSTextField (431.0, 292.0, 41.0, 16.0) newView NSTextField (18.0, 316.0, 416.0, 16.0) newView NSProgressIndicator (53.0, 289.0, 372.0, 20.0) newView NSButton (440.0, 0.0, 40.0, 25.0) newView NSBox (5.0, 286.0, 465.0, 5.0) newView NSTextField (6.0, 291.0, 41.0, 16.0) newView KaraokeSongDragDestinationView (0.0, 0.0, 490.0, 340.0) newView NSButton (438.0, 306.0, 49.0, 32.0) 2021-03-14 17:09:02.334430+0100 BugCode[50871:3973128] HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine 2021-03-14 17:09:02.371983+0100 BugCode[50871:3973074] Metal API Validation Enabled
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’21
Reply to Custom NSView crashes app but runs fine in Xcode
I looked at doc for: func instantiate(withOwner owner: Any?, topLevelObjects: AutoreleasingUnsafeMutablePointerNSArray??) - Bool Parameters owner The object to set as the Nib’s owner (File’s Owner). topLevelObjects On return, an array containing the top-level objects of the nib. Return Value true if the nib is instantiated; otherwise false. Discussion Unlike legacy methods, the objects adhere to standard Cocoa memory management rules; it is necessary to keep a strong reference to the objects or the array to prevent the nib contents from being deallocated.  Outlets to top level objects should be strong references to demonstrate ownership and prevent deallocation. But you pass nil for topLevelObjects. Could you try changing to follow those requirements ? Some info here: https://stackoverflow.com/questions/41312945/instantiate-nsview-with-custom-objects-in-it-using-nsnib Other solution (I usually use): I do not declare IBOutlets I create objects in the NSView subclass and Draw them in draw() func.
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’21
Reply to App crashes at start under iOS 13.x, runs fine with iOS 14
What are the targets defined for the app ? 13 or 14 ? Does the crash occur on device, on simulator, on both ? I don't use SwiftUI in my code (besides maybe the SceneDelegate ? No, SceneDelegate has no link in itself to SwiftUI. When you defined the app, did you define as UIKit lifecycle ? Did you try an option-clean build folder ? Have you a file named chauffeur (either chauffeur.swift or chauffeur.xib) ? If so, please post code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Custom NSView crashes app but runs fine in Xcode
I get many errors in Xcode: 2021-03-14 13:39:24.562545+0100 BugCode[44764:3798589] CDN - client insert callback function client = 0 type = 17 function = 0x7fff322a4246 local_olny = false 2021-03-14 13:39:24.562599+0100 BugCode[44764:3798589] CDN - client setup_remote_port 2021-03-14 13:39:24.562627+0100 BugCode[44764:3798589] CDN - Bootstrap Port: 1799 2021-03-14 13:39:24.562771+0100 BugCode[44764:3798589] CDN - Remote Port: 23599 (com.apple.CoreDisplay.Notification) 2021-03-14 13:39:24.562812+0100 BugCode[44764:3798589] CDN - client setup_local_port 2021-03-14 13:39:24.562834+0100 BugCode[44764:3798589] CDN - Local Port: 23811 2021-03-14 13:39:24.578916+0100 BugCode[44764:3798626] [plugin] AddInstanceForFactory: No factory registered for id CFUUID 0x60000024c1e0 F8BB1C28-BAE8-11D6-9C31-00039315CD46 2021-03-14 13:39:24.636908+0100 BugCode[44764:3798626]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine You have defined KaraokeSongDragDestinationViewDelegate But no-one conforms to it. Is it because you have just ket a bug-report part of code ? Note: I was also missing the "icon_play" but replaced by another image.
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’21
Reply to How do I connect a control to a method programmatically? - Develop In Swift Fundamentals - Programmatic Actions
I looked at the book. On page 272, they add the IBAction by control-drag. They do not declare an IBOutlet here, because they don't need it yet (just need the IBAction) On page 287, they now need to reference the button, hence they have created the IBOutlet and connected it to the button in IB. « In order to connect the button to a method programmatically, you’ll need a reference to the button in code. Use Interface Builder to create an IBOutlet for the button.» You can do it, either by control drag from the button to the code and select IBOutlet (similar to what they explain for IBAction and to what is explained on page 282. or declare IBOutlet in code and control- drag to the button in IB to connect it: That is what they assume Page 287: In the book, they do not create the button programmatically. In fact, they create it in IB. If you declare an IBOutlet, you have to connect to the object in IB. Otherwise when you reference the button, you get the crash Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value. However, if you really wanted to create the button completely programmatically, you must not declare an IBOutlet, just a var. So change code as follows: class ViewController: UIViewController { @IBOutlet var toggle: UISwitch! // you may have to do as with button @IBOutlet var slider: UISlider! // you may have to do as with button    var button: UIButton! // -- No IBOutlet override func viewDidLoad() { super.viewDidLoad()   button = UIButton(frame: CGRect(x: 80, y: 30, width: 100, height: 30)) // -- Create the button button.setTitle("My button", for: UIControl.State.normal) // Select a better title button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside) view.addSubview(button) // -- so that button appears in view - could also write self.view to make it clearer } Note: when you connect the button from IB to its IBOutlet, that is somehow the code for initialising button is added automatically when the VC is loaded from storyboard.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Can I make my app fully dark?
As you noticed, it is technically possible, with several options: https://stackoverflow.com/questions/56537855/is-it-possible-to-opt-out-of-dark-mode-on-ios-13 It is not totally clear if it is authorized to disable light mode, even though there does not seem to be restrictions in Apple Guidelines, except a recommendation to support both. https://stackoverflow.com/questions/58816289/will-apple-reject-my-app-if-i-force-light-mode-on-my-app So the safest is probably to design the app directly with the colors you want in each view.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’21
Reply to Unbalanced calls to begin/end appearance transitions for...
In UserDefaults.standard.set(downloadUrl, forKey: "profile_picture_url") let vc = self?.storyboard?.instantiateViewController(identifier: "tabBarVC") as! TabBarViewController vc.modalPresentationStyle = .fullScreen self?.present(vc, animated: true) Note: why optional chaining self? and not just self. Did you try to present in the main thread ? let vc = self.storyboard?.instantiateViewController(identifier: "tabBarVC") as! TabBarViewController vc.modalPresentationStyle = .fullScreen DispatchQueue.main.async { self.present(vc, animated: true) }
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21