使用视图控制器作为模态视图控制器和选项卡栏视图控制器

发布于 2024-09-26 07:45:13 字数 894 浏览 4 评论 0原文

我有一个类似于 iPhone 中的联系人的视图控制器。代码是这样的,

tabBarController = [[UITabBarController alloc] init];
friendsVC = [[RemittanceFriendsVC alloc] initWithNibName:@"RemittanceFriendsView" bundle:nil];
friendsVC.friendsArray = [[RemittanceModel getInstance] friends];
UINavigationController *friendsNVC = [[UINavigationController alloc] initWithRootViewController: friendsVC];
[controllers addObject:friendsNVC];
tabBarController.viewControllers = controllers;

RemittanceFriendsVC 是 UITableViewController,单击单元格将进入详细信息视图。我在 ViewController (VC) 中设置了“模态”变量,以了解其是否作为模态加载。由于它是选项卡栏项目的一部分,(非模式视图)它工作正常。但是当我将其加载为模态 VC 时,当我单击表格单元格时,我想关闭模态视图,但它并没有关闭模态视图。

在friendVC中,这是行不通的,

-(void) didPressCancelButton {
        [self.navigationController dismissModalViewControllerAnimated:YES];
}

我想做的是,使用相同的VC作为选项卡栏项目,有时作为模态VC。难道不可能吗?

I have a view controller alike contacts in iPhone. The code is something like this,

tabBarController = [[UITabBarController alloc] init];
friendsVC = [[RemittanceFriendsVC alloc] initWithNibName:@"RemittanceFriendsView" bundle:nil];
friendsVC.friendsArray = [[RemittanceModel getInstance] friends];
UINavigationController *friendsNVC = [[UINavigationController alloc] initWithRootViewController: friendsVC];
[controllers addObject:friendsNVC];
tabBarController.viewControllers = controllers;

The RemittanceFriendsVC is UITableViewController, clicking on a cell takes to details view. I have 'modal' variable set in the ViewController (VC)to know if its loaded as modal or not. Since its part of a tab bar item, (non modal view) it works fine. But when I am loading it as modal VC, when I click on a table cell, I want to dismissmodalview, but it did not dismiss the modal view.

In the friendVC this is not working,

-(void) didPressCancelButton {
        [self.navigationController dismissModalViewControllerAnimated:YES];
}

What I wanted to do is, use the same VC as a tab bar item and sometime as a modal VC. Isn't it possible?

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

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

发布评论

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

评论(1

锦欢 2024-10-03 07:45:13

好吧,应该是这个问题

[self.navigationController dismissModalViewControllerAnimated:YES];

[self dismissModalViewControllerAnimated:YES];

然后就可以正常工作了。

okay, it was the problem with the

[self.navigationController dismissModalViewControllerAnimated:YES];

it should be,

[self dismissModalViewControllerAnimated:YES];

Then it works fine.

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