我已经完成了第1步和第2步,但在实现了在步骤3中讨论的自定义绑定后,我收到了以下错误
无法为此绑定计算Scheme,因为此CustomBinding缺少TransportBindingElement。每个绑定必须至少有一个派生自TransportBindingElement的绑定元素。
我的自定义绑定代码如下:
UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(60, 60, 200, 60)];
btn.backgroundColor=[UIColor greenColor];
[btn setTitle:@"btn" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(clickme:) forControlEvents:UIControlEventTouchUpInside];
...
- (void) clickme: (UIButton*) sender{
[self.navController pushViewController:ANOTHER_VIEW_CONTROLLER animated:YES];
}
我的web.Config如下:
public class MyCustomBinding : Binding
{
private HttpTransportBindingElement transport;
private BinaryMessageEncodingBindingElement encoding;
public MyCustomBinding()
: base()
{
this.InitializeValue();
}
public override BindingElementCollection CreateBindingElements()
{
BindingElementCollection elements = new BindingElementCollection();
elements.Add(this.encoding);
elements.Add(this.transport);
return elements;
}
public override string Scheme
{
get { return this.transport.Scheme; }
}
private void InitializeValue()
{
this.transport = new HttpTransportBindingElement();
this.encoding = new BinaryMessageEncodingBindingElement();
}
}
public class MyCustomBindingCollectionElement : BindingCollectionElement
{
// type of custom binding class
public override Type BindingType
{
get { return typeof(MyCustomBinding); }
}
// override ConfiguredBindings
public override ReadOnlyCollection<IBindingConfigurationElement> ConfiguredBindings
{
get
{
return new ReadOnlyCollection<IBindingConfigurationElement>(
new List<IBindingConfigurationElement>());
}
}
// return Binding class object
protected override Binding GetDefault()
{
return new MyCustomBinding();
}
public override bool ContainsKey(string name) {
return true;
}
protected override bool TryAdd(string name, Binding binding, Configuration config)
{
return true;
}
}