I am adding a SwiftUi view to my story board via UIHostController. The integration works and I have full functionality of buttons and image taps, however the Tabview at the bottom of the screen requires a long press in order for the Tabview to work and switch for me. If I run the same SwiftUI file within a swift application (no uikit, nor uihostcontroller) it works as intended. It has to be something with the UIhostcontroller or the way I am wrapping the swiftui view. Again the tabview does work but it would take someone forever to figure out you have to press and hold the button to get the page to switch. Anyone know what might be going on?
import UIKit
import SwiftUI
import FirebaseAuth
import FirebaseAuthUI
class ViewController: UIViewController {
let contentView = UIHostingController(rootView: ContentView())
override func viewDidLoad(){
super.viewDidLoad()
// Do any additional setup after loading the view.
addChild(contentView)
view.addSubview(contentView.view)
setupConstraints()
}
fileprivate func setupConstraints(){
contentView.view.translatesAutoresizingMaskIntoConstraints=false
contentView.view.topAnchor.constraint(equalTo:view.topAnchor).isActive=true
contentView.view.bottomAnchor.constraint(equalTo:view.bottomAnchor).isActive=true
contentView.view.leftAnchor.constraint(equalTo:view.leftAnchor).isActive=true
contentView.view.rightAnchor.constraint(equalTo:view.rightAnchor).isActive
= true
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
Image download from right click "Context Menu" not responding in the web page loaded in WKWebview. If any body knows help me to identify which delegate method will receive this call or is there any manual implementation needed to get this option work.
App:Mac Application. Language : Objective C. SDK: Xcode
You can intercept context menu items of the WKWebView class by subclassing it and implementing the willOpenMenu method like this:
class MyWebView: WKWebView {
override func willOpenMenu(_ menu: NSMenu, with event: NSEvent) {
for menuItem in menu.items {
if menuItem.identifier?.rawValue == "WKMenuItemIdentifierDownloadImage" ||
menuItem.identifier?.rawValue == "WKMenuItemIdentifierDownloadLinkedFile" {
menuItem.isHidden = true
}
}
}
}
I am developing for tvOS at the moment and I have added a UISegmentedControl, this gets focused automatically by the tvOS focus engine. When I added a UIButton, this became the first focused item.
How I do go about setting the first focused item and being able to navigate between them?
Add a read only preferredFocusedView property to your view controller that returns the view you would like to start focused:
override weak var preferredFocusedView: UIView? {
get {
return segmentedControl
}
}
I want to be able to accept drops on my app's dock icon from files, URLs, and text. Since files (public.file-url) are a subtype of URL (public.url), I added just two Services entries to my Info.plist:
Services
Item 0 (processURL)
Instance method Name = processURL
Send Types
Item 0 = public.url
Menu
Menu item title = Process URL
Item 1 (processString)
Instance method Name = processString
Send Types
Item 0 = public.plain-text
Menu
Menu item title = Process Text
Then I made my -applicationDidFinishLaunching call [NSApp setServicesProvider: self], and wrote a couple methods (-processString:userData:error and -processURL:userData:error) there in my application delegate. The app icon now accepts drops of all three types. In the -processURL:... method, it's easy to check if it's a local file or not, so that handles both of those cases.
One case still eludes me, though. When I try dragging a window's proxy icon to the app, it highlights the icon as if it can accept the drop, but then my method isn't called.
I tried dropping proxy icons from Xcode, Terminal, Preview, and some third-party apps: none would call my services method. But strangely, a proxy icon dropped from the Finder worked fine.
I tried changing public.url to public.item (the base type of the physical hierarchy), but my method is still not called for non-Finder proxy icons.
When the Finder successfully drops a proxy icon on my app, the pboard -types it provides are:
"public.file-url",
"CorePasteboardFlavorType 0x6675726C",
"dyn.ah62d4rv4gu8y6y4grf0gn5xbrzw1gydcr7u1e3cytf2gn",
NSFilenamesPboardType,
"dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu",
"Apple URL pasteboard type"
I tried using each of these directly as the "Send Types". "public.file-url" and "NSFilenamesPboardType" highlight the icon as if it'll accept the drop, but don't. The others, unsurprisingly, don't even highlight the dock icon.
I can't find any reference to proxy icons having a different UTI than normal files. Do they? That would be weird.
I know this must be possible, because I can drag proxy icons from any window onto a Terminal window. What am I missing?
UPDATE: From an NSView, if I -registerForDraggedTypes including "public.url", I do get drops of proxy icons from all apps, with exactly the same -types list as from the Finder, listed above. So it's clearly something special to receiving drops via the dock icon. This should still be possible somehow: you can drag a proxy icon from a (non-Finder) window (e.g., an .xcworkspace from Xcode) onto the Terminal dock window, and it catches that just fine.
Swift 4 for your app delegate
func application(_ sender: NSApplication, openFile: String) -> Bool {
Swift.print("sender \(sender) file \(openFile)")
return true
}
func application(_ sender: NSApplication, openFiles: [String]) {
Swift.print("sender \(sender) list \(openFiles)")
// Create a FileManager instance
let fileManager = FileManager.default
for path in openFiles {
do {
let files = try fileManager.contentsOfDirectory(atPath: path)
for file in files {
_ = self.application(sender, openFile: file)// void return
}
}
catch let error as NSError {
print("Yoink \(error.localizedDescription)")
}
}
}
If you implement dragging files to your dock icon using application:openFile: in your NSApplicationDelegate, then dragging proxy icons should work too. The trick to accepting all files is adding a Document Type with extensions of '*'.
The app I'm working on consists of a hierarchy of data and a filter to search through that data. The data is displayed in a hierarchy of table views, and navigation through that hierarchy works fine. However, when I try to navigate to my filter view model (which is shown as a modal view controller), I run into problems.
The first time I open the modal view, everything works fine, and I can close it and all navigation still works. When I try to open it a second time, however, the modal view will appear and the app will freeze and crash after a couple of seconds.
Here is the code from my custom presenter (which is a subclass of MvxModalSupportTouchViewPresenter) that is handling the modal navigation request:
public override void Show (IMvxTouchView view)
{
if (view is IMvxModalTouchView) {
var newNav = new UINavigationController ();
newNav.PushViewController (view as UIViewController, false);
newNav.NavigationBar.TintColor = UIColor.Black;
PresentModalViewController (newNav, true);
return;
...
(taken from MvvmCross Using a modal ViewController from a Tab)
I close the modal by dismissing it in the view itself. Does anyone have any idea why the app is crashing?
follow up on this by email was...
"As to my previous question, I found where the error was. The view
associated with my modal view model got into an infinite loop of
Dispose() calls. It would only happen if the modal was shown multiple
times. Commenting out the Dispose() method allowed me to open it
multiple times."
Not sure currently whether this was a fault in the mvx framework or in the app code - but thought I'd post this here in case it helps others