dotnet / dotnet/macios

UIBarButtonItemAppearance does not proxy the title property from UIBarItem

Open
#7,168 1 comment 0 reactions 0 assignees View on GitHub
bug iOS
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 12h
Merged PRs (30d)
123

Description

Included project is just Xamarin.iOS so moved issues from here https://github.com/xamarin/Xamarin.Forms/issues/7785

## Summary
When 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.`

## API Changes

From IOS 13 , `SetValueForKey ` method useing key with `_cancelButtonText `can not work in VS and Xcode.
However , xcode has another way to realize it before IOS 9.0:

` [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"Cancel"]
`
After IOS 9.0 has the follow way :

`[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]].title = @"Cancel";`

Unfortunately , they all not found in VS .

e.g.

1. Create an Xamarin IOS project , and then add a UISearchBar in StoryBoard ,calls MySearchBar
2. Set `MySearchBar.SetShowsCancelButton(true, true);`
3. Use `MySearchBar.SetValueForKey(new NSString("Click"), new NSString("_cancelButtonText"));`

```
Managed Stacktrace:
=================================================================
at <0xffffffff>
at ObjCRuntime.Messaging:void_objc_msgSend_IntPtr_IntPtr <0x00112>
at Foundation.NSObject:SetValueForKey <0x002ca>
at AppiOS3.ViewController:ViewDidAppear <0x00888>
at :runtime_invoke_void__this___byte <0x00350>
at <0xffffffff>
at UIKit.UIApplication:UIApplicationMain <0x00251>
at UIKit.UIApplication:Main <0x000b2>
at UIKit.UIApplication:Main <0x00132>
at AppiOS3.Application:Main <0x00092>
at :runtime_invoke_void_object <0x00342>
=================================================================

```
And only can set `TintColor`:

`UIBarButtonItem.AppearanceWhenContainedIn(typeof(UISearchBar)).TintColor = UIColor.Red;
`
Not found property `Text `or `Title `the same as Xcode.

## Intended Use Case
So link : https://stackoverflow.com/questions/58188633/xamarin-problems-with-uisearchbars-cancel-button-in-ios-13

Sample-Link: https://www.dropbox.com/s/3rmksed1jn3nfmj/AppIOSFour.rar?dl=0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.