Find object button In Xamarin IOS - xamarin.ios

I am new in IOS and using websync tech to sync data and keep update price button, but how can I find the object button in IOS? In Android it can use findbyId function, Isn't got any solution? I using this setValueForKey function but always get error.
Name: NSUnknownKeyException Reason: [<SA_IOS_MatchScreen 0x7fab255c4730> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key TG01.

I think you can use ViewWithTag! Just remember set tag value.
Then you can use tag to find your button.
I tried it and it works!
* Don't set tag = 0 because it's default value is 0;
UIButton btn1 = this.View.ViewWithTag(1) as UIButton;
btn1.Enabled = false;
btn1.SetTitle("Change!",UIControlState.Normal);

Related

Can't select value in combo box using Coded UI Test

WinComboBox comboxBox = new WinComboBox();
comboxBox.SearchProperties[WinComboBox.PropertyNames.Name] = "Server:";
comboxBox.WindowTitles.Add("Server Settings");
comboxBox.SearchProperties[WinComboBox.PropertyNames.TechnologyName] = "Server";
comboxBox.SearchProperties[WinComboBox.PropertyNames.ControlName] = "comboBoxPlatforms";
comboxBox.SelectedItem = "Value3";
I used above code for selecting a value in a combo box using Coded UI test.
But I am getting the error
System.NotSupportedException: GetProperty of "SelectedItem" is not supported on control type: Window
Can anyone tell me what I am doing wrong or show me an alternative solution?
Sometimes i add this : comboxBox.TechnologyName = “MSAA”;
I think WindowTitles is not needed.
Try also
Mouse.click (comboBox) and playback.wait(1000); above comboxBox.SelectedItem = "Value3"; To exclude some common problems. If that solves your issue then you can start refactoring.
Ik hope it helps.
As the exception points out, the UITestControl object you have is of ControlType WINDOW, which is why you are not able to do SetProperty on it.
I will specify parent control also while searching.
WinComboBox comboxBox = new WinComboBox(WinWIndow Parent);
If your control is WinCombobox try:
combobox.SetProperty("SelectedItem", "Value3");
Also If you know the index of the item try:
combobox.SetProperty("SelectedIndex", 3);
Let me know if it resolves your issue

CodenameOne - Layered Layout import not working

According to the docu of LayeredLayout here (JavaDoc), there is an inset method that can be used for relative positioning. I created a bare pones CN1 project and added this piece, also from the docu:
Container cnt = new Container(new LayeredLayout());
LayeredLayout ll = (LayeredLayout)cnt.getLayout();
TextField searchField = new TextField();
Button btn = new Button("Search");
cnt.add(searchField).add(btn);
ll
.setInsets(searchField, "1mm auto auto auto")
.setInsets(btn, "0 auto auto 0")
.setReferenceComponentLeft(btn, searchField, 1f)
.setReferenceComponentTop(btn, searchField, 0);
However, I am getting an error that the setInset Method is not found. Looking at the source of LayeredLayout class reveals that it indeed does not have this method.
The method setInsets(TextField, String) is undefined for the type LayeredLayout
I just updated CN1 lib to the latest version as of today.
Any idea?
I suggest updating your plugin.
In Codename One Settings select Basic and click Update Client Libs.

How to hide shortcut bar in iOS9 UIWebview?

I would like to hide bar which is on top of keyboard (undo, redo, copy and back, forward buttons) when user clicks on textfield in UIWebView.
Does anybody know how to do it?
Thanks!
Using method swiziling we can remove the keyboard shortcut bar (only works with ObjC).
- (void)hideKeyboardShortcutBar
{
Class webBrowserClass = NSClassFromString(#"UIWebBrowserView");
Method method = class_getInstanceMethod(webBrowserClass, #selector(inputAccessoryView));
IMP newImp = imp_implementationWithBlock(^(id _s) {
if ([self.webView respondsToSelector:#selector(inputAssistantItem)]) {
UITextInputAssistantItem *inputAssistantItem = [self.webView inputAssistantItem];
inputAssistantItem.leadingBarButtonGroups = #[];
inputAssistantItem.trailingBarButtonGroups = #[];
}
return nil;
});
method_setImplementation(method, newImp);
}
inputAccessoryView
: This property is typically used to attach an accessory view to the
system-supplied keyboard that is presented for UITextField and
UITextView objects.
So the new implementation block will be fired every time the keyboard pops up.
I posted this answer in Hide shortcut keyboard bar for UIWebView in iOS 9 as well
I am able to hide those using these lines
let item:UITextInputAssistantItem = self.textFieldName.inputAssistantItem
item.leadingBarButtonGroups = []
item.trailingBarButtonGroups = []
Hope this will help.

UITextView undo manager do not work with replacement attributed string (iOS 6)

iOS 6 has been updated to use UITextView for rich text editing (a UITextView now earns an attributedText property —which is stupidly non mutable—). Here is a question asked on iOS 6 Apple forum under NDA, that can be made public since iOS 6 is now public...
In a UITextView, I can undo any font change but cannot undo a replacement in a copy of the view's attributed string. When using this code...
- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new
{
1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old];
2. old=new;
}
... undoing is working well.
But if I add a line to get the result visible in my view, the undoManager do not fire the "replace:with:" method as it should...
- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new
{
1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old];
2. old=new;
3. myView.attributedText=[[NSAttributedString alloc] initWithAttributedString:old];
}
Any idea? I have the same problem with any of the replacement methods, using a range or not, for MutableAttributedString I tried to use on line "2"...
Umm, wow I really didn't expect this to work! I couldn't find a solution so I just started trying anything and everything...
- (void)applyAttributesToSelection:(NSDictionary*)attributes {
UITextView *textView = self.contentCell.textView;
NSRange selectedRange = textView.selectedRange;
UITextRange *selectedTextRange = textView.selectedTextRange;
NSAttributedString *selectedText = [textView.textStorage attributedSubstringFromRange:selectedRange];
[textView.undoManager beginUndoGrouping];
[textView replaceRange:selectedTextRange withText:selectedText.string];
[textView.textStorage addAttributes:attributes range:selectedRange];
[textView.undoManager endUndoGrouping];
[textView setTypingAttributes:attributes];
}
Mac Catalyst (iOS14)
UITextView has undoManager that will manage undo and redo for free without any additional code.
But replacing its attributedText will reset the undoManager (Updating text and its attributes in textStorage not work for me too). I found that undo and redo will works normally when formatting text without replacing attributedText but by standard edit actions (Right click on highlighting text > Font > Bold (Mac Catalyst)).
So to fix this :
You need to set the allowsEditingTextAttributes of UITextView to be true, this will make UITextView support undo and redo of attributedText.
self.textView.allowsEditingTextAttributes = true
If you want to change the text of attributedText, use replace(_:withText:) of UITextInput, or insertText(_:) and deleteBackward() of UIKeyInput that UITextView conforming to.
self.textView.replace(self.textView.selectedTextRange!, withText: "test")
If you want to change attributes of text, use updateTextAttributes(conversionHandler:) of UITextView instead.
self.textView.updateTextAttributes { _ in
let font = UIFont.boldSystemFont(ofSize: 17)
let attributes: [NSAttributedString.Key: Any] = [
.font: font,
]
return attributes
}
For changing text and its attributes in specific range, modify the selectedRange of UITextView.
To implement undo and redo buttons, check this answer : https://stackoverflow.com/a/50530040/8637708
I have tested with Mac Catalyst, it should work on iOS and iPadOS too.
The Undo Manager is reset after setting its 'text' or 'attributedText' property, this is why it does not work. Whether this behavior is a bug or by design I don't know.
However, you can use the UITextInput protocol method instead.
(void)replaceRange:(UITextRange *)range withText:(NSString *)text
This works.

Set value for YUI Menu Button

I'm trying to set the assigned value to a YUI Menu Button in order to use values from previous operations.
Something like remembering previous choices.
For label I already know that I can change it with:
button.set("label", "my label")
unfortunatelly I cannot change the value using: button.set("value", "my value")
Any ideia on how can I do this?
Other way would be to force a selection, but I have no ideia on how to do that.
Thanks
just found out that you can use:
var menu = button.getMenu();
var item = menu.getItem(index);
button.set("selectedMenuItem", item);
all that is left for me now is finding the needed index

Resources