Show ViewController on Extension info button Edit Mode - macos

I am working on an Today Extension for Yosemite.
I would like to show a SettingsViewController instead of going into edit mode.
If I "presentViewControllerInWidget" on "widgetDidBeginEditing" it gets some weird glitches and the view controller is hiding and showing all the time.
Did anyone achieved to show an viewController on info button click or knows a workaround on that glitch?
func widgetDidBeginEditing() {
self.presentViewControllerInWidget(self.settingsViewController)
}

This worked for me:
func widgetDidBeginEditing() {
var delay = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(delay, dispatch_get_main_queue()) {
self.presentViewControllerInWidget(self.settingsViewController)
}
}

I guess this is a bug that made it into the Yosemite release.
Documentation on widgets is very sketchy at best and it seems there are quite a few oddities in the framework.
When adding a symbolic breakpoint to widgetDidBeginEditing I get two hits when clicking the little edit button, and the edit Button becomes "Cancel". It is supposed to say "Done" though. Only after an "Add" action should it say "Cancel" (Just check out Apple's Weather widget)
Important to say: I am not using the template with the NCWidgetListViewController but my own list implementation.
If anyone finds a proper solution to this problem I'd be very happy!

Related

What does "invalid mode 'kCFRunLoopCommonModes' ..."mean?

Environment: Version 11.0 beta 3 (11M362v)
Here's the full text:
invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug.
This message will only appear once per execution.
Hello World
This message only appears when I click on a UISwitch button that is connected to an action; here, printing "Hello World".
Apparently the behavior of the action isn't affected.
As a comparison, I've created a UIBarButtonItem in the toolbar which behaves normally. So there's something fishy about the switch button.
Question: why would this appear and what does it mean? Remedy?
I think it's a warning that Apple should fix it itself. Even in this sample project which is from WWDC19 this problem exists. There is a UISwitch in a cell of a table. When I tap it, the mentioned warning is raised.
So, in my view, it is a bug that Apple should deal with.
Judging from the replies by Apple Developer Relations to this post, this is a bug in UIKit and one that Apple is tracking. Until the bug is fixed, the advice is to treat this as "log noise".
I had a similar problem:
When I got the call-back from the UISwitch, I reloaded the UITableView.
I think that the call-back is initiated before the UISwitch finishes changing its context, and reloading the cell in that state creates some conflict.
With that theory, I solved my problem like so:
I separated the cells into sections, where the cell with the UISwitch was in its own section.
When I got the call-back from the UISwitch, I reloaded all the sections except the section that has the cell with the UISwitch.

UI Button - activate buttons with keyboard input

this is probably dead easy but I can't find a solution. I made a dialogue system and have a UI-button to click when the player should display a sentence next.
The issue is that the button is only triggered onMouseclick and I would like to change the input button to Enter. Would anyone know how to go about this?
If you need to determine if the button is selected first or not, I suggest you take a look at this page: https://docs.unity3d.com/ScriptReference/UI.Selectable.IsHighlighted.html
If you don't want pressing the button to have any functionality, you just wouldn't link it to any functions.
Working code might look something like this:
public class selectableExample : Selectable{
BaseEventData _event;
void Update()
{
if (IsHighlighted(_event) == true)
{
if (Input.GetKeyDown("enter")){
print("replace me with working function"); // whatever you want to have happen on button press
}
}
}
}
You simply attach this to your button and it should respond the same as being pressed. To be honest, it hardly seems like you actually need a button at all for this though, you'd probably be fine with just a label telling the player to press "Enter" and then simply checking for that input.
You can use the Event Trigger component to use one of the many event types. Select Submit (this is set to enter and return in the input settings at edit>project settings>input by default).
Don't set anything in the OnClick event.
The only thing needed now is to actively highlight the button from somewhere with ReferenceToButton.Select().

Tab Bar Ignoring UITraitCollection requests - 6 Tabs Desired

I'm using the following code to trick my application into believing it's an iPad and displaying 6 tabs on the tab bar.
-(UITraitCollection *)traitCollection
{
UITraitCollection
*realTraits = [super traitCollection],
*lieTrait = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
return [UITraitCollection traitCollectionWithTraitsFromCollections:#[realTraits, lieTrait]];
}
This is all well and good, apart from when returning from a SFSafariViewController which I've rotated a couple of times. The issue I'm having is that the tab bar defaults back and shows four tabs along with the more page. What's my issue? It's important to note that just opening the SFSafariViewController and then going back DOESN'T trigger the Tab Bar to default - so I'm presuming it has something to do with the rotation putting a new view on top (a view which is ignoring the UITraitCollection call).
I've subclassed the SFSafariViewController and UITabBarController, while trying to call the method above when ever possible to stop the Tab Bar defaulting - however I'm having no success.
NOTE: I am getting a, '[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction' error when rotating - if that is of any help.
Thank You.
I ended up solving this by implementing the snippet below into my suclassed UINavigationController.
- (UITraitCollection *)overrideTraitCollectionForChildViewController:(UIViewController *)childViewController
{
return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
}
Hope that helps someone else with the problem!

How to deselect the contents of a TextField in swift

I have a simple desktop app where a TextField should be focused when the window loads. I have this working, but it's a little annoying that, having loaded the users content into the TextField, the entire contents of the field become selected automatically. The user may want to start editing the content, but they will rarely/never want to replace it all at once (imagine a text editor doing this, to see what I mean).
I see there is an Action for selectAll: but what I want is the opposite Action of selectNone:
I tried passing nil to the selectText method, but that doesn't work:
textField.selectText(nil)
I found a number of answers on StackOverflow that mention a selectedTextRange, but this appears to be outdated, because Xcode 6.3 doesn't recognize this as a valid property on TextField.
Can anyone explain how I do this?
It's been a while since I've dealt with NSTextFields to this level (I work mostly in iOS these days).
After doing a little digging I found this on the net:
NSText* textEditor = [window fieldEditor:YES forObject:textField];
NSRange range = {start, length};
[textEditor setSelectedRange:range];
window is the window containing your field, textField.
This requires the field editor to be managing your field, what can be done simply by previously selecting the whole text of the field using the selectText:sender method.
Here is the final swift code that I got working based on what Duncan C posted:
if let window = NSApplication.sharedApplication().mainWindow {
let textEditor = window.fieldEditor(true, forObject: textField)!
let range = NSRange(0..<0)
textEditor.selectedRange = range
}

Need to Click Popup with Gm script that is not always there

i'm still having a problem clicking a popup button on an auction site,that appears only if u won an auction. This popup seems tbe a problem. Ive managed to get help partially in Need to click a bid button with Grease monkey script, i'm able to get the bid buttons clicked, but the popu is stil a problem. The xpath for the popup is:
.//*[#id='ctl00_mainContentPlaceholder_Button3']
And the script i'm using currently is:
// ==UserScript==
// #name click popup try1.3
// #include http://www.trada.net/*
// ==/UserScript==
// ctl00_mainContentPlaceholder_Button3
function PopClick ()
{var PopBtn1=document.getElementById("ctl00_mainContentPlaceholder_Button3");
alert('try1');
PopBtn1.click (1);
alert('finished');
};
PopClick();
But the problem seems to be that the script doesnt stay active on the page waiting for the popup, I think if i can get it to "wait" for the popup to appear, it should work. I'm very new to GM, so excuse if there is simple errors. I had exelent help from people like Brock sofar, who is showing me the ropes. Slowly but surely I'm gettin the hang of it. Remove the alerts, i just used them to see if it executing.
The simplest solution would be to run this function, say every second, thus "waiting" for the popup to appear:
setInterval(PopClick, 1000);
It is also better to rewrite PopClick to check if the element is there, before calling click, like this:
function PopClick () {
var PopBtn1=document.getElementById("ctl00_mainContentPlaceholder_Button3");
if(PopBtn1) {
PopBtn1.click ();
// It is also makes sense to clear interval here. see docs for setInterval/clearInterval please :)
}
};
May be this will help you with the freezing issue.
The more proper way, however, would be to set up MutationEvent listener. Since you are using Firefox, it should work OK:
function click_if_popup(evt) {
if(evt.target.hasAttribute('id') && evt.target.getAttrubute('id') =="ctl00_mainContentPlaceholder_Button3")
evt.target.click();
}
document.addEventListener('DOMNodeInsertedIntoDocument', click_if_popup);
Sorry, I didn't test any of this code: I wanted just to give you the general idea of where to dig.

Resources