我使用Mac的Visual Studio来开发我的Xamarin表单应用程序,并将其设置为定期下载稳定的更新。我收到了一条消息,将XCode升级到版本9,然后我做到了。我的应用程序中的网格中有一个搜索框,这无法再次工作。我只得到下面的错误消息。有什么想法我如何解决这个问题?如果我评论搜索框,它可以正常工作,但我需要它。
Objective-C例外。名称:nsinternalinconsistencyException 原因: - [uisearchbar sizethatfits:]不支持通过 非有限值({inf,56})本机堆栈跟踪:0 CoreFoundation 0x0000000103A971CB __ exceptionpreprocess 171 1 libobjc.a.dylib
0x0000000111115DF41 OBJC_EXEPTION_THROW 48 2 COREFOUNDATION
0x0000000103A9C362 [nSexception rish:格式:参数:] 98 3
基金会0x00000001046C2089 - [nsassertionhandler handlefailureInmethod:对象:文件:linenumber:description:] 193 4
UIKIT 0x0000000107E9802B- [UISEARCHBAR sizethatfits:] 347 5文章
0x000000010333f8f49 xamarin_dyn_objc_msgsend 217 6 ???
0x000000013198FF40 0x0 5127077696 7 ???
0x00000001319847a2 0x0 5127030690
我在这里找到了答案。
- 在iOS中为搜索栏创建一个自定义渲染器
- 覆盖 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);
}
}
}