c# - Xamarin.iOS Objective-C 绑定(bind)错误

标签 c# ios objective-c binding xamarin.ios

我正在尝试绑定(bind):https://www.cocoacontrols.com/controls/tsvalidatedtextfield用于 Xamarin.iOS。

到目前为止,我已经使用 Objective-C 代码编译了一个静态库,并使用 Objective-Sharpie 生成了 API 定义。

对于其中两个属性,我收到了一个错误:

Error CS0246: The type or namespace name `NSRegularExpression' could not be found. Are you missing an assembly reference? (CS0246) (TSValidatedTextField)

Error CS0246: The type or namespace name `ValidationBlock' could not be found. Are you missing an assembly reference? (CS0246) (TSValidatedTextField)

没有任何意义。据我所知,NSRegularExpression 是我导入的 Foundation 框架的一部分(using MonoTouch.Foundation)。

我将如何修复这些错误?如果这两个属性被注释掉,绑定(bind)就会编译。

如有任何帮助,我们将不胜感激。

谢谢你们。

using System;
using System.Drawing;
using MonoTouch.ObjCRuntime;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace TSValidatedTextField
{

public enum ValidationResult {
    Passed = 0,
    Failed,
    ueTooShortToValidate
}

[BaseType (typeof (UITextField))]
public partial interface TSValidatedTextField {

    [Export ("regexpPattern")]
    string RegexpPattern { get; set; }

    [Export ("regexp")]
    NSRegularExpression Regexp { get; set; } //ERROR

    [Export ("isValid")]
    bool IsValid { get; }

    [Export ("regexpValidColor")]
    UIColor RegexpValidColor { get; set; }

    [Export ("regexpInvalidColor")]
    UIColor RegexpInvalidColor { get; set; }

    [Export ("validatedFieldBlock", ArgumentSemantic.Copy)]
    ValidationBlock ValidatedFieldBlock { get; set; } //ERROR

    [Export ("validWhenType")]
    bool ValidWhenType { [Bind ("isValidWhenType")] get; set; }

    [Export ("looksForManyOccurences")]
    bool LooksForManyOccurences { [Bind ("isLooksForManyOccurences")] get; set; }

    [Export ("occurencesSeparators")]
    NSObject [] OccurencesSeparators { get; set; }

    [Export ("minimalNumberOfCharactersToStartValidation")]
    uint MinimalNumberOfCharactersToStartValidation { get; set; }
}

}

最佳答案

NSRegularExpressionValidationBlock不属于 Xamarin.iOS .

这并不意味着您被困在那里。就像你绑定(bind)TSValidatedTextField一样,你可以自己绑定(bind)它们。

完成后,最好标记 NSRegularExpression Regexp { get; set; }[Internal]并编写一些自定义代码来公开 .NET System.Text.RegularExpressions.Regex , 在 C# 中使用起来更自然。

关于c# - Xamarin.iOS Objective-C 绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20356390/

相关文章:

ios - 使用 ##__VA_ARGS__ 时 Xcode 编译器错误

c# - C/C++/C#: how to force repaint of window chrome on windows 7?

c# - 如何创建 System.IO.Stream 流的实例

iphone - 花栗鼠物理学 : Velocity question

ios - 持久化 Firebase 实时数据库在快照中创建空值

ios - iPhone 上的复选框 : Left Border Cut Off

ios - 从 iOS 应用程序中的 UIAlertView 文本框检索值

c# - 使用 XML 或 OOP 技术处理数据的相对处理速度是多少? (即 XProc 或 XSL 与 C# 或 Java)

c# - 使只读属性在派生类中可写

ios - 使 iPhone 6/6 plus 自动调整应用程序大小