当我们从我的签名收到响应时,我希望在我的整个应用程序中显示警告框
这怎么可能呢?
我们可以使用NSNotification吗?
发布于 2011-05-06 18:28:57
你可以把一个公共方法放在你的应用程序中,让它显示你的警报视图。
您可以像这样访问应用程序委托:
[UIApplication sharedApplication].delegate您需要将其强制转换为您的应用程序委托类,以防止出现警告,然后您可以发送消息:
[(MyAppDelegate *)[UIApplication sharedApplication].delegate showMyAlertView];发布于 2011-05-06 18:29:47
- (void)afterSignIn
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}发布于 2011-05-06 18:34:25
创建和接收通知非常简单:
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将在YourViewController上调用someEventHappend方法
https://stackoverflow.com/questions/5910000
复制相似问题