我正在尝试绑定(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; }
}
}
最佳答案
NSRegularExpression
和 ValidationBlock
不属于 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/