[英]Why does my UIButton delegate have to execute entirely before changes are shown in view?
I'm doing some MonoTouch development, and I really can't figure out an problem I've run into 我正在做一些MonoTouch开发,我真的无法弄清楚我遇到的问题
I'm having an ViewController containing a UIButton. 我有一个包含UIButton的ViewController。 I have added a delegate to the TouchDown event of this button. 我已将一个委托添加到此按钮的TouchDown事件中。 In this delegate I'm calling a WebService and trying to change the colour and title of the button. 在这个委托中,我正在调用WebService并尝试更改按钮的颜色和标题。 However nothing happens to the button before the entire delegate have been executed. 但是,在执行整个委托之前,按钮没有任何反应。 The thing is that the webservice is rather slow, so I want to give the users a waiting message by changing the colour and title of the button. 问题是web服务很慢,所以我想通过改变按钮的颜色和标题给用户一个等待的消息。
The code: 编码:
public override void ViewDidLoad ()
{
View.BackgroundColor = UIColor.Black;
bookButton = new UIButton( new RectangleF(10,100,this.View.Frame.Width-10 ,40) );
bookButton.BackgroundColor = UIColor.Clear;
setButton();
bookButton.TouchDown += delegate {
gymClass.book();
setButton();
tableView.ReloadData();
NavigationController.PopViewControllerAnimated( true );
};
this.View.AddSubview( bookButton );
}
Anyone, please? 有人吗?
委托在负责渲染的主线程上执行,因此您将阻止渲染器,直到您返回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.