当我们收到我的登录回复时,我想在我的整个应用程序中显示警报框
怎么可能?
我们可以使用NSNotification
吗?
创建和接收通知很简单:
YourViewController
1)在您的通知中添加一个观察者(例如,它的):
[[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
您可以在您的 appdelegate 中放置一个公共方法并让它显示您的警报视图。
您可以像这样访问应用程序委托:
[UIApplication sharedApplication].delegate
您需要将其转换为您的应用程序委托类以防止出现警告,然后您可以发送消息:
[(MyAppDelegate *)[UIApplication sharedApplication].delegate showMyAlertView];
- (void)afterSignIn
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
@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