In my application there is a floating button. Its function is to open available screens from anywhere.
Scenario
Suppose I have 4 screens and in each screen their is floating Button.
1. Home Screen
2. Services Screen
3. Contact Screen
4. Events
Now suppose I have opened all screens. And currently I am in Contact Screen and I want to go to Services.
Then I have to push services again thus creating the object of Services Screen. This creates a problem as if the user gooes 10 times to Services then 10 new objects will be created.
How can I implement this scenario ?
My Code:
if([sender tag]==1)
{
[push home];
}
else if([sender tag]==2)
{
[push services];
}
else if([sender tag]==3)
{
[push Contact];
}
else
{
[push events];
}
Try with this.
UIViewController *popViewController = //assign here Services Screen or what view you want to back
BOOL isExist = NO;
for (UIViewController *viewController in self.navigationController.viewControllers) {
if ([viewController isEqual:popViewController]) {
isExist = YES;//exist view controller. so you should not create a new one
[self.navigationController popViewControllerAnimated:YES];
}
}
if (isExist==NO) {//not exist view controller. so you should create a new one
[self.navigationController pushViewController:YourViewController animated:YES];
}
我更喜欢使用UITabBarController
。
@NSUser, sorry for not answering your exact problem, but I would recommend using UIPageViewController
for "hosting" and presenting your content view controllers one at a time. Here is a conceptual document from Apple with essential description and how-to's. Good luck.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.