NS通知问题

发布于 2024-11-05 14:27:02 字数 84 浏览 2 评论 0原文

当我们收到我的登录响应时,我想在整个应用程序中显示警报框,

这怎么可能?

我们可以使用 NSNotification 吗?

i want to show the alert box in my whole applicaton when we got the response from my Signin

how it is possible?

can we use NSNotification?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦太阳 2024-11-12 14:27:02

您可以在您的应用程序委托中放置一个公共方法,并让它显示您的警报视图。

您可以像这样访问应用程序委托:

[UIApplication sharedApplication].delegate

您需要将其转换为应用程序委托类以防止出现警告,然后您可以发送消息:

[(MyAppDelegate *)[UIApplication sharedApplication].delegate showMyAlertView];

You could put a public method in your appdelegate and let it show your alertview.

You can access the app delegate like this:

[UIApplication sharedApplication].delegate

You'll need to cast it to you app delegate class to prevent a warning, then you can send the message:

[(MyAppDelegate *)[UIApplication sharedApplication].delegate showMyAlertView];
坐在坟头思考人生 2024-11-12 14:27:02
- (void)afterSignIn
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

}
- (void)afterSignIn
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

}
挥剑断情 2024-11-12 14:27:02

创建和接收通知很简单:

1) 将观察者(例如,YourViewController)添加到您的通知中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someEventHappend) 
                                                 name:@"SomeEvent" object:nil];

您应该在 viewDidLoad 方法中添加此代码。

2) 在 YourViewController 中实现 someEventHappend 方法

3) 当您从登录获得 git 响应时发布通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"SomeEvent" object:nil];

之后 NSNotificationCenter 将调用 someEventHappend YourViewController 上的 方法

It's simple to create and receive notifications:

1) Add an observer (for example, it's YourViewController) to your notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someEventHappend) 
                                                 name:@"SomeEvent" object:nil];

You should add this code in viewDidLoad method.

2) Implement someEventHappend method in YourViewController

3) Post notification when you've git response from Signin:

[[NSNotificationCenter defaultCenter] postNotificationName:@"SomeEvent" object:nil];

After that NSNotificationCenter will call someEventHappend method on YourViewController

贩梦商人 2024-11-12 14:27:02

@anil 取一个并在 Global.h "BOOL Signin" 值中设置它。当它为 true 时
然后显示
你像这样改变视图

-(void)afterSignIn
{
    if(Signin == YES)
    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Meassage" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

并不强制使用 NSNotificationCenter

@anil take one and set this in Global.h "BOOL Signin" value .When When it's true
Then show
Your alter view like this

-(void)afterSignIn
{
    if(Signin == YES)
    {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Meassage" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

it is not compulsory to use NSNotificationCenter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文