我有一个继承自UIButton的自定义按钮。我正在处理TouchUpInside事件,并希望在当前视图的顶部显示视图。在Windows开发中是否存在像Dialog这样的东西?或者我应该以另一种方式做到这一点?
[MonoTouch.Foundation.Register("HRPicker")]
public class HRPicker : UIButton
{
public HRPicker () : base()
{
SetUp();
}
public HRPicker(NSCoder coder) : base(coder)
{
SetUp();
}
public HRPicker(NSObjectFlag t) : base(t)
{
SetUp();
}
public HRPicker(IntPtr handle) : base(handle)
{
SetUp();
}
public HRPicker(RectangleF frame) : base(frame)
{
SetUp();
}
public void SetUp()
{
TouchUpInside += HandleTouchUpInside;
}
void HandleTouchUpInside (object sender, EventArgs e)
{
//I want to display a View here on top of the current one.
}
}
谢谢,
答案 0 :(得分:2)
是的,您有几个选择:
ModalViewController:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
UIPopoverController:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverController_class/Reference/Reference.html
WEPopoverController:https://github.com/mono/monotouch-bindings/tree/master/WEPopover
更新:无论您使用哪个选项,都必须从主线程调用Popover / Modal视图的演示文稿:
using(var pool = new NSAutoReleasePool()) {
pool.BeginInvokeOnMainThread(()=>{
// Run your awesome code on the
// main thread here, dawg.
});
}
答案 1 :(得分:0)
Cocoa中对等的对话框是UIAlertView:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
查看此问题以获取如何使用它的示例:Showing an alert with Cocoa
代码应该很容易转换为c#和MonoTouch。但这是一个简单的例子:http://monotouchexamples.com/#19