PushViewController:HomeButton 无需每次重新加载
我的 iPhone 应用程序中的每个视图都有一个自定义 homeButton,并且按照我编写代码的方式,它会重新加载 homeView,其中包含带有所有其他按钮的菜单页面。相反,我观察到当我单击后退按钮(navigationItem)时,它不会重新加载页面。我也想为我的 HomeButton 实现类似的功能,以便我的应用程序更加高效。这是我目前编写的代码。任何人都可以帮我获取 viewController 而不是再次重新加载它。谢谢
-(void)homButtonClicked{
if(homeView == nil)
homeView = [[ViewController alloc]init];
[self.navigationController pushViewController:homeView animated:YES];
}
I have a custom homeButton in my iphone app on every view and the way I have written code, it reloads the homeView-which has the menu page with all the other buttons. On the contrary, I observe that when I click the back button(navigationItem), it does not reload the page. I would like to implement a similar functionality for my HomeButton too so that my app is much more efficient. This is the code I have written currently. Can anyone help me just fetching the viewController instead of reloading it again. Thanks
-(void)homButtonClicked{
if(homeView == nil)
homeView = [[ViewController alloc]init];
[self.navigationController pushViewController:homeView animated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,每次单击“主页按钮”时,您都希望加载属于
ViewController
类的homeView
。为什么不直接加载ViewController
作为UINavigationController
的初始视图控制器。每次单击主页按钮时,调用函数[self.navigationController popToRootViewControllerAnimated:YES];
哪个将是您的ViewController
主菜单?If I understand correctly each time you click on 'home button', you would like to load
homeView
which is ofViewController
class. Why don't you just load theViewController
as the initial view controller of yourUINavigationController
. And each time you click on the home button, call the function[self.navigationController popToRootViewControllerAnimated:YES];
which will be yourViewController
home menu?