1

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

怎么可能?

我们可以使用NSNotification吗?

4

4 回答 4

0

创建和接收通知很简单:

YourViewController1)在您的通知中添加一个观察者(例如,它的):

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

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

2)实现someEventHappend方法在YourViewController

3)当您收到来自 Signin 的 git 响应时发布通知:

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

之后NSNotificationCenter将调用someEventHappend方法YourViewController

于 2011-05-06T10:34:25.490 回答
0

您可以在您的 appdelegate 中放置一个公共方法并让它显示您的警报视图。

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

[UIApplication sharedApplication].delegate

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

[(MyAppDelegate *)[UIApplication sharedApplication].delegate showMyAlertView];
于 2011-05-06T10:28:57.437 回答
0
- (void)afterSignIn
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];

}
于 2011-05-06T10:29:46.753 回答
0

@anil 取一个并将其设置在 Global.h "BOOL Signin" 值中。当它为真时然后显示您的更改视图,如下所示

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

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

不强制使用 NSNotificationCenter

于 2011-05-06T10:39:09.220 回答