gpt4 book ai didi

ios - UIBarButtonItem - 如何弹出 "done"按钮?

转载 作者:行者123 更新时间:2023-11-28 19:20:17 25 4
gpt4 key购买 nike

我有一个带有“完成”按钮的导航 Controller 。当用户完成表单时,他们按“完成”,我希望该 View 从堆栈中弹出并返回主菜单。

这是我目前得到的代码:

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
style:UIBarButtonItemStylePlain
target:self
action:[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES]];
self.navigationItem.rightBarButtonItem = anotherButton;

求助!谢谢

最佳答案

你试试这个怎么样:

UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
style:UIBarButtonItemStylePlain
target:self
action:@selector(onClickOfDone);
self.navigationItem.rightBarButtonItem = anotherButton;

现在在名为onClickOfDone的方法中编写popViewController逻辑

- (void)onClickOfDone {
[self.navigationController popViewControllerAnimated:YES];
}

如果您的 pop 仅返回一级,那么上面的代码会有所帮助。如果你想指定它必须弹出到的 Controller ,那么你可以使用

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES]

编辑:

您还可以使用 SystemItem 完成:

UIBarButtonItem *aDoneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
target:self action:@selector(onClickOfDone)];
self.navigationItem.rightBarButtonItem = aDoneButton;
[aDoneButton release];

关于ios - UIBarButtonItem - 如何弹出 "done"按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9511776/

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