简体   繁体   中英

Xamarin problems with UISearchBar's cancel Button in iOS 13

I'm developing a mobile application using Xamarin.iOS and now i've just updated the Xamarin's latest version, to have compatiblity with the new iOS 13. So far i was changing the text of the UISearchBar cancel button using SetValueForKey but now it tells me that ivar is prohibited. This is an application bug ivar is prohibited. This is an application bug .

例外

Can you help with alternatives to change the UISearchBar's cancel button text?

EDIT

Thanks to @Junior Jiang - MSFT it was given a quick fix here .

[System.Runtime.InteropServices.DllImport ("/usr/lib/libobjc.dylib", EntryPoint = "objc_msgSend")]
public extern static void void_objc_msgSend_IntPtr (IntPtr receiver, IntPtr selector, IntPtr arg1);

var app = UIBarButtonItem.AppearanceWhenContainedIn (typeof (UISearchBar));
using (var title = new NSString ("Cancel"))
    void_objc_msgSend_IntPtr (app.Handle, ObjCRuntime.Selector.GetHandle ("setTitle:"), title.Handle);
app.TintColor = UIColor.Red;

Unfortunately , this method can not works now in IOS 13.

Even though through OC menthod to do, it also can not work.

[searchBar setValue("Cancel", forKey: "_cancelButtonText")];
//not work in xcode

In Xcode, there is new way to implement it,

searchBar.showsCancelButton = YES;

[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"Cancel"];
//before IOS 9

[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]].title = @"Cancel";
//after IOS 9

However, in Xamarin we can not find the methods, just only can set TintColor:

UIBarButtonItem.AppearanceWhenContainedIn(typeof(UISearchBar)).TintColor = UIColor.White;

The property Text not found in UIBarButtonItem .

Then I have added it to the feature issue in GitHub Xamarin. Here is the link , you can follow it up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM