【发布时间】:2012-03-16 12:39:47
【问题描述】:
nilMy 应用程序需要运行一些检查,然后可能会在我的应用程序激活时显示UIAlertView。为此,我已注册 didBecomeActiveNotification 并在此处运行我的检查。
每当我的UIAlertView 在初始启动期间弹出时,就会出现问题,它会导致“应用程序在应用程序结束时应该有一个根视图控制器启动”消息。我猜这是因为UIAlertView 显示在viewDidAppear: 之前。
如果不在didBecomeActiveNotification 中,我应该如何触发我的UIAlertView?
2012-03-16 12:21:47.238 App[4181:707] viewDidLoad:
2012-03-16 12:21:47.462 App[4181:707] didBecomeActiveNotification:
2012-03-16 12:21:47.793 App[4181:707] Applications are expected to have a root view controller at the end of application launch
2012-03-16 12:21:48.500 App[4181:707] viewDidAppear:
编辑:要在新项目中触发此操作,请执行以下操作。
1 个新项目 -> 单视图应用程序
2 在 Viewcontroller.m 中将以下内容添加到 viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActiveNotification:) name:UIApplicationDidBecomeActiveNotification object:nil];
3 在 ViewController.m 中添加以下方法
-(void)didBecomeActiveNotification:(NSNotification *)notification
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil];
[alertView show];
[alertView release];
}
4 构建和运行
【问题讨论】:
-
你是如何注册
didBecomeActiveNotification的? -
在
viewdidLoad内部使用[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didBecomeActiveNotification:) name:UIApplicationDidBecomeActiveNotification object:nil]; -
我试图在 app-delegate 在
applicationDidBecomeActive和处显示一个警报,在根视图控制器的didBecomeActiveNotification处使用您提供的代码注册 - 两者都有效。你认为你的应用有什么特别之处吗,也许是根视图控制器初始化? -
我不是说它不工作,它工作正常。我刚刚收到控制台警告,想弄清楚原因。
-
不幸的是(或者也许幸运的是)我没有看到这样的警告。您能否确认该消息仅在显示警报时可见,而没有警报则没有此类消息?顺便说一句,它真的是编译器警告还是控制台消息?
标签: ios xcode uialertview compiler-warnings nsnotifications