IOS使用presentModalViewController显示某些控制器
我使用presentModalViewController来显示一些控制器 A controller://it 将显示B的控制器并接收消息,当它接收消息时,我想知道B是否显示IOS使用presentModalViewController显示某些控制器,ios,uinavigationcontroller,push-notification,message,Ios,Uinavigationcontroller,Push Notification,Message,我使用presentModalViewController来显示一些控制器 A controller://it 将显示B的控制器并接收消息,当它接收消息时,我想知道B是否显示 -(void)viewDidLoad{ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recvPushMessage:) name:RECV_PUSH_MESSAGE_NOTIFY object:nil];
-(void)viewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recvPushMessage:) name:RECV_PUSH_MESSAGE_NOTIFY object:nil];
}
-(void)buttonAction(id)sender{
B* b = [B alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:(UIViewController*)b];
[self presentModalViewController:navigationController animated:YES];
//release
}
-(void)recvPushMessage{
//i want to kown B is it show or not
if(b is showing){
//do something
}
else{
//do something for A
}
}
B controller://when B是显示的,我不想在A中调用recvPushMessage
-(void)viewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recvPushMessage:) name:RECV_PUSH_MESSAGE_NOTIFY object:nil];
}
-(void)recvPushMessage{
//do something for B
}
检查这是否是你要找的
-(void)recvPushMessage{
if (self.presentedViewController) { //check if you have this model view controller
//do something
}
else{
//do something for A
}
}
对于self.modalViewController
更新:
对于第二个问题,您可以获取导航控制器的topViewController
,并将其与C进行比较。您可以使用类似[self.modalViewController topViewController]
的方法检查它是否为C,然后继续
例如:-
if ([[(UINavigationController *)self.modalViewController topViewController] isKindOfClass:[C class]])
presentedViewController必须是IOS5.0,4.3怎么样?在该版本中,您可能必须使用
self.modalViewController
。让我试试,如果B推一些控制器,如“C”,并且C也收到消息,我怎么知道presentedViewController是CA@ACB在他的情况下,self.presentedViewController将是UINavigationController。所以他需要从中获取根视图控制器&然后与“b”进行比较controller@Rahul,你现在只看到了问题。我假设他是直接显示B。在这种情况下,只有我的第一个选项有效。