Xamarin NSNotificatioCenter:我怎样才能NSObject的传递? [英] Xamarin NSNotificatioCenter: How can I get the NSObject being passed?

查看:360
本文介绍了Xamarin NSNotificatioCenter:我怎样才能NSObject的传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的应用程序发布在视图中通知使用NSNotificationCenter另一个。所以在我的目的地类创建我的观察如下:

I am trying to post a notification in a view from my app to another one using NSNotificationCenter. So in my destination class I create my observer as follows:

NSNotificationCenter.DefaultCenter.AddObserver ("ChangeLeftSide", delegate {ChangeLeftSide(null);});

和我有我的方式:

public void ChangeLeftSide (UIViewController vc)
{
    Console.WriteLine ("Change left side is being called");
}

现在从另外的UIViewController我张贴通知如下:

Now from another UIViewController I am posting a notification as follows:

NSNotificationCenter.DefaultCenter.PostNotificationName("ChangeLeftSide", this);



我怎么能访问在我的帖子通知传递我的目标类视图控制器?在iOS中这是非常简单的,但我似乎无法找到我的MonoTouch的(Xamarin)...

How can I access the view controller that is being passed in my post notification in my destination class? In iOS it is very straight forward but I cannot seem to find my way in monotouch (Xamarin)...

推荐答案

办法找到我答案,在这里是需要对我张贴在问题的代码所做的更改:

I found the answer, here are the changes that need to be made on the code I posted in the question:

public void ChangeLeftSide (NSNotification notification)
{
    Console.WriteLine ("Change left side is being called");
    NSObject myObject = notification.Object;
    // here you can do whatever operation you need to do on the object
}

和观察者创建:

NSNotificationCenter.DefaultCenter.AddObserver ("ChangeLeftSide", ChangeLeftSide);

现在,你可以投或键入检查NSObject的,并用它做什么!完成!

Now you can cast or type check the NSObject and do anything with it! Done!

这篇关于Xamarin NSNotificatioCenter:我怎样才能NSObject的传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆