首页 文章

由于Xcode 9升级,网格错误消息中的搜索框

提问于
浏览
0

我使用visual studio for Mac开发我的Xamarin表单应用程序并将其设置为定期下载稳定更新 . 我收到一条消息,要将我的Xcode升级到版本9,我做了 . 我的应用程序中的网格中有一个搜索框,但无法再次使用 . 我得到的只是下面的错误信息 . 我有什么想法可以解决这个问题吗?如果我在搜索框中注释掉它可以工作,但我需要它 .

抛出Objective-C异常 . 名称:NSInternalInconsistencyException原因: - [UISearchBar sizeThatFits:]不支持传递非有限值({inf,56})本机堆栈跟踪:0 CoreFoundation 0x0000000103a971cb __exceptionPreprocess 171 1 libobjc.A.dylib 0x000000011115df41 objc_exception_throw 48 2 CoreFoundation 0x0000000103a9c362 [NSException raise :format:arguments:] 98 3基础0x00000001046c2089 - [NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 193 4 UIKit 0x0000000107e9802b - [UISearchBar sizeThatFits:] 347 5 Articles.iOS 0x00000001033f8f49 xamarin_dyn_objc_msgSend 217 6 ??? 0x000000013198ff40 0x0 5127077696 7 ??? 0x00000001319847a2 0x0 5127030690

1 回答

  • 1

    我找到了答案here .

    • 在iOS中为SearchBar创建自定义渲染器

    • Override SizeThatFits方法

    • 返回一些默认大小

    using System;
            using PROJ.iOS.Renders;
            using Xamarin.Forms;
            using Xamarin.Forms.Platform.iOS;
    
            [assembly: ExportRenderer(typeof(SearchBar), typeof(CustomSearchbarRenderer))]
            namespace PROJ.iOS.Renders
            {
                public class CustomSearchbarRenderer : SearchBarRenderer
                {
                    public CustomSearchbarRenderer()
                    {
                    }
                    public override CoreGraphics.CGSize SizeThatFits(CoreGraphics.CGSize size)
                    {
                        return new CoreGraphics.CGSize(30, 30);
                    }
                }
            }
    

相关问题