iPhone SDK问题:在TabBarControlled Views中加载Ta​​bleView

发布于 2024-09-11 03:48:19 字数 1048 浏览 1 评论 0原文

我遇到了一个问题,现在一整天都找不到解决方案。我是 iPhone SDK 的新手,所以我想我只是错过了一些东西。

我的应用程序由 TabbedNavigation 组成,具有三个 ViewController。一切都按预期进行。现在,当用户点击按钮(而不是选项卡按钮...)时,我想打开一个新视图(最好是从 NIB)。按钮的操作方法按预期调用。但是,我没有加载新的(表)视图。

我尝试给你一些代码来解释我的情况:

首先,在我的应用程序的委托的 didFinishLaunchingWithOptions 中,我加载 tabBarController 的视图(TabBarController 是委托的属性):

 // Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

当应用程序启动时,会显示 TabController 的第一个 ViewController,如下所示预期的。该 viewController 有其自定义 ViewController 类,其中包含按钮的操作方法。我的操作方法如下所示:

-(IBAction)filtersButtonPressed:(id)sender {

  FiltersTableViewController *filtersViewController = 
    [[FiltersTableViewController alloc] initWithNibName:@"Filters" bundle:nil];

  [[[super tabBarController] navigationController] pushViewController:filtersViewController];
}

不知何故,这不起作用......我当然尝试了几件事 - 但没有成功。

你们中有人能指出我正确的方向吗?只需按一下按钮即可进入新视图并不是那么困难...

提前致谢!

谢尔·帕维

I've a problem and cannot find a solution to the whole day now. I'm new to iPhone SDK, so I guess I'm just missing something.

My app consists of a TabbedNavigation, having three ViewControllers. Everything works as expected. Now I want to open a new view (preferably from a NIB) when the user tabs a button (not the tab buttons...). The button's action method is called as expected. However, I don't get the new (table-)view loaded.

I try to give you some code that explains my situation:

First, in my Application's delegate's didFinishLaunchingWithOptions I load the tabBarController's view (the TabBarController is a property of the delegate):

 // Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];

The first ViewController of the TabController is shown when the app is startet, as expected. This viewController has its custom ViewController class in which the action-method for the button sits. My action method looks like this:

-(IBAction)filtersButtonPressed:(id)sender {

  FiltersTableViewController *filtersViewController = 
    [[FiltersTableViewController alloc] initWithNibName:@"Filters" bundle:nil];

  [[[super tabBarController] navigationController] pushViewController:filtersViewController];
}

This, somehow, is not working... I have tried several things of course - with no success.

Can someone of you guys point me in the right direction? It cannot be that hard just to get to a new view by the press of a button...

Thanks in advance!

Chers, pawi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最冷一天 2024-09-18 03:48:19

建议您尝试将新的“过滤器”视图显示为模式视图控制器。尝试将代码更改为:

-(IBAction)filtersButtonPressed:(id)sender {

   FiltersTableViewController *filtersViewController = 
      [[FiltersTableViewController alloc] initWithNibName:@"Filters" bundle:nil];
[self presentModalViewController:filtersViewController animated:YES];

这会将过滤器视图控制器向上滑动到当前视图的顶部(尽管您可以根据需要更改动画效果)。要摆脱这个问题,当用户完成视图后,调用

[self dismissModalViewControllerAnimated:YES];

编辑:
如果您确实想使用导航控制器将视图推送到堆栈上,请使用

[self.navigationController pushViewController:filtersViewController];

Suggest you try showing the new "Filters" view as a modal view controller. Try changing your code to:

-(IBAction)filtersButtonPressed:(id)sender {

   FiltersTableViewController *filtersViewController = 
      [[FiltersTableViewController alloc] initWithNibName:@"Filters" bundle:nil];
[self presentModalViewController:filtersViewController animated:YES];

This will slide up the filters view controller (although you can change the animation effect if you want) on top of your current view. To get rid of this, when the user has finished with the view, call

[self dismissModalViewControllerAnimated:YES];

Edit:
If you really want to use the navigation controller to push the view onto the stack, use

[self.navigationController pushViewController:filtersViewController];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文