gpt4 book ai didi

ios - 从 UIView 子类调用 popViewControllerAnimated

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:01:08 26 4
gpt4 key购买 nike

我在 UIView 子类中创建了一个按钮。我需要通过此按钮调用 popViewControllerAnimated,但没有任何效果!而且我看不到 viewController 推回到 rootViewController 。这是我的代码:

- (void)SomeFunction {

backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton showsTouchWhenHighlighted];

[backButton addTarget:self
action:@selector(backToMainMenu)
forControlEvents:UIControlEventTouchUpInside];

}

- (void)backToMainMenu {

[self.window.rootViewController.navigationController popViewControllerAnimated:YES];

NSLog(@"back");
}

我把代码改成这样:

UINavigationController *vc = self.window.rootViewController.navigationController;
[vc.navigationController popViewControllerAnimated:YES];

但什么也没发生。

最佳答案

我认为您需要使用将按钮作为参数的正确目标格式。所以像这样添加目标函数:

[backButton addTarget:self
action:@selector(backToMainMenu:)
forControlEvents:UIControlEventTouchUpInside];

目标应该是这样的:

- (void) backToMainMenu:(UIButton *) sender{
[self.navigationController popViewControllerAnimated:YES];
}

关于ios - 从 UIView 子类调用 popViewControllerAnimated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29076259/

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