Iphone 如何从AppDelegate(推送后)检查哪个UIViewController处于活动状态
是否可以检查代码中哪个UIViewController场景处于活动状态 我有一个推送通知进入应用程序,并希望根据用户所处的视图执行不同的操作,如下所示: AppDelegate:Iphone 如何从AppDelegate(推送后)检查哪个UIViewController处于活动状态,iphone,objective-c,Iphone,Objective C,是否可以检查代码中哪个UIViewController场景处于活动状态 我有一个推送通知进入应用程序,并希望根据用户所处的视图执行不同的操作,如下所示: AppDelegate: - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { if (tableViewController == active) //get data
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
if (tableViewController == active)
//get data from server
else if (detailedViewController == active)
//Get Image from server
}
谢谢发布本地通知:
[NSNotificationCenter defaultCenter] postNotificationName:@"foo" object:whatever];
并让所有适当的ViewController监视它:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleFoo:)
name:@"foo"
object:nil];
ViewController会根据需要添加或删除观察者
if ( _viewController.isViewLoaded == YES)
{
NSLog(@"Yes");
}
else
{
NSLog(@"No");
}
希望,这将帮助您…我猜您使用了一些contaneir视图控制器。如果您使用的是
UITabBarController
,您可以要求自己提供以下信息:
@property(nonatomic, assign) UIViewController *selectedViewController
或其:
@property(nonatomic) NSUInteger selectedIndex
如果您使用的是UINavigationController
:
@property(nonatomic, readonly, retain) UIViewController *visibleViewController
如果您喜欢对容器进行细粒度控制,则可以使您的Appdelegate符合相应的委托协议:UITabbarControllerDelegate
和UINavigationControllerDelegate