gpt4 book ai didi

IOS 使用 presentModalViewController 显示一些 Controller

转载 作者:行者123 更新时间:2023-12-01 16:52:45 24 4
gpt4 key购买 nike

我使用 presentModalViewController 来显示一些 Controller 。

A Controller ://它将显示B的 Controller 并接收消息,当它收到消息时,我想知道B是否显示?

-(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 ://当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
}
}

对于版本 < iOS 5.0,您可以使用 self.modalViewController .

更新:
对于第二个问题,您可以获取 topViewController导航 Controller 并将其与 C 进行比较。您可以使用类似 [self.modalViewController topViewController]检查它是否是C,然后继续。

例如:-
if ([[(UINavigationController *)self.modalViewController topViewController] isKindOfClass:[C class]])

关于IOS 使用 presentModalViewController 显示一些 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14352678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com