大家好,
我已经创建了一个带有选项卡视图控制器的测试项目,单击选项卡时,它将转到相应的屏幕(例如屏幕A),当我单击屏幕A中的后退按钮时,它将返回主页,但没有选项卡视图,
类名,
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithNibName:nil bundle:nil];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
//avController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:addNavigationController animated:YES];
以下是后退按钮的可能代码,其中 DataEntry 是我导航到上面代码的
[self.navigationController dismissModalViewControllerAnimated:YES];
如果我使用以下代码,它将正常工作&我会使用选项卡返回主页,但它不会运行 viewDidLoad 中更新的代码,因此我需要导航到主页,而不是使用 disstedModalViewController
任何人都可以告诉我当我导航到主页时如何获取 tabView不使用dismissModalViewController的页面
hii every one
i have created a test project with tab view controller, on click of a tab it will goto that coresponding screen(say screen A) when i click back button in screen A it will come back to main page but with out tabView,
following is may code for back button where DataEntry is a class name to where i am navigating
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithNibName:nil bundle:nil];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
//avController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:addNavigationController animated:YES];
insted of the above code if i use following code
[self.navigationController dismissModalViewControllerAnimated:YES];
it will work fine & ill get back to main page with tabs , but it wont run the updated code which is in the viewDidLoad so i need to navigate to the main page insted of using dismissModalViewController
can any one tell me how can i get tabView when i navigate to the main page with out using dismissModalViewController
发布评论
评论(2)
我正在努力理解你的问题,但 viewDidLoad 仅在视图加载时运行:而不是在你返回屏幕 A 时运行:那时它仍然加载。要在每次显示屏幕 A 时运行代码,请查看 viewWillAppear / viewDidAppear http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
我倾向于以编程方式创建选项卡,而不是使用IB:发生的事情更清楚了。看看这个答案,看看我是如何做到的。
代码中带有 UINavigationController 的 UITabBar
I'm struggling a little to understand your problem, but viewDidLoad only runs when the view loads: not when you come back to screen A : its still loaded then. To run code each time screen A is displayed, take a look at viewWillAppear / viewDidAppear http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
I tend to create tabs programatically rather than using the IB: its clearer whats going on. Take a look at this answer to show how I do it.
UITabBar with UINavigationController in code
这是不正确的:
[self.navigationControllerpresentModalViewController:addNavigationControlleranimated:YES];
(这不是你想要的:它将呈现一个模式视图,当你关闭它时,它会发现什么在下面,即您的选项卡)
您应该使用
pushViewController
来显示您的avController
以便激活后退按钮等等。看看这个。
this is not correct:
[self.navigationController presentModalViewController:addNavigationController animated:YES];
(this is not what you mean to have: it will present a modal view, when you dismiss it, it will uncover what was below, i.e. your tab)
you should use
pushViewController
to show youravController
so that the back button is activated and so on.look at this.