ios - 如何从包含我的 UIViewController 的 UITableViewController 中显示新 View ?

标签 ios objective-c view properties

我在 UIViewController 中有一个 UITableViewController。虽然此 TableView Controller 是唯一涉及的 Controller ,但当用户点击一行时,它可以很好地推送 View 。然而,自从我将它移动到 UIViewController 中包含的两个之一后,行的点击突然不起作用。

我已经tried searching around我不是第一个遇到这个问题的人,但没有一个答案适合我的情况,或者问题没有有效的答案。该链接是我发现的最接近的链接,但我没有使用 Storyboard ——我使用的是单独的 XIB。

那么如何从 View Controller 内的 View Controller 推送新 View ?

回顾一下:

  1. 这是我所拥有的,它在将用户带到新屏幕方面效果很好!

    // Normal table behavior, as illustrated by [another question][2].
    
    - (void)tableView:(UITableView *)tableView 
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        SomeView *detailViewController = [[SomeView alloc] initWithNibName:@"SomeView" bundle:nil];
    
        // Pass the selected object to the new view controller.
        [self.navigationController pushViewController:detailViewController animated:YES];
    }
    
  2. 现在我将 viewcontroller 作为 View 中的属性 - 并且上面的代码位于 tableviewcontroller 文件中而不是“主” View 中,不会导致出现新屏幕不再这样了!


感谢您的评论!这是一些代码来阐明我的场景。

  1. Controller 中的 Controller 。这是来 self 一直用来测试这个概念的测试项目的文件。在本例中,我在 TableView Controller 中有一个 TableView Controller 。

    @interface SimpleTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
    
    // This is the controller within the controller
    @property IBOutlet SecondTableViewController *secondTableController;
    @property IBOutlet UITableView *secondTable;
    
  2. 我的 SecondTableViewController 有这个有趣的地方。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Navigation logic may go here. Create and push another view controller.
    
        UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:@"SimpleNonTableViewController" bundle:nil];
        // ...
        // Pass the selected object to the new view controller.
        [manualViewControllerParent.navigationController  pushViewController:detailViewController animated:YES];
    }
    

用户交互的 View 连接到SimpleTableViewController。这样,SecondTableViewController 就“在”SimpleTableViewController 之内。如果您想了解更多详细信息,请随时发表评论!


我已将我的测试/概念项目放在 github 上。 https://github.com/hyliandanny/TableViewCeption

最佳答案

您需要使用自定义容器 Controller 来执行您想要的操作。如果您使用 Storyboard,这将是最简单的,但您也可以使用 xibs 在代码中完成。外部 Controller 应该是 UIViewController,而不是 TableView Controller 。您可以执行以下操作(在外部 Controller 中):

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    UIViewController *detailViewController = [[UIViewController alloc] initWithNibName:@"SimpleNonTableViewController" bundle:nil];
    [self addChildViewController:detailViewController];
    detailViewController.view.frame = set the frame to what you want;
    [self.view addSubview:detailViewController.view];
    [detailViewController didMoveToParentViewController:self];
}

您应该阅读 Apple 的自定义容器 Controller 文档。

关于ios - 如何从包含我的 UIViewController 的 UITableViewController 中显示新 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14470093/

相关文章:

ios - Swift 中的条件绑定(bind)错误

ios - UIPickerView:在展开可选值时意外发现 nil

iOS:使用解析连接到 MongoDB

objective-c - 处理隐藏的错误 Objective C

objective-c - 如何将 AppleScript 菜单添加到我的菜单栏?

android - 扩展 View 并使用 onLongclick

android - 对 Activity/fragment 和垃圾收集中的 View 的强引用

ios - 在行内滚动项目的一些问题

ios - 创建带有圆形边框 iOS 的 UIImageView

Android:颜色变化后触发重绘