同一 ViewController 内的 UITableView segue
UITableView segue within the same ViewController
我有一个 UIViewController,其中包含连接在一起的地图和 tableView,它看起来像这样:
而且我希望能够将 tableView 推送到同一视图控制器中的另一个 tableView,以便地图保持原样。当然,我希望能够使用左上角导航栏中出现的按钮以编程方式向后展开 segue。
在放置在弹出窗口中的 iPad tableView 控制器中可以观察到类似的行为。我将如何在 Swift (iOS 8) 中执行此操作?
非常感谢任何代码片段或指向现有代码示例的指针。
这在技术上不是 "push" -- 当用户在您的 table 视图中选择一个单元格时,触发对 table 视图委托方法的调用
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
...您应该从屏幕右侧引入第二个 table 视图。
您的每个 table 视图数据源和委托方法都应该区分第一个和第二个 table 视图。这是 cellForRowAtIndexPath 的示例:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView1 {
return self.collection1.count
} else if tableView == self.tableView2 {
return self.collection2.count
}
return 0;
}
您可以像这样实现视图控制器包含:
- (void)viewDidLoad {
[super viewDidLoad];
// Setup the container view
_containerView = [[UIView alloc] initWithFrame: // DESIRED FRAME];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_containerView];
// Setup the main view controller
[self addChildViewController:_mainViewController];
_mainViewController.view.frame = _containerView.bounds;
[_containerView addSubview:_mainViewController.view];
[_mainViewController didMoveToParentViewController:self];
}
现在您可以在单独的视图控制器中创建两个 table 视图。听起来您应该向主视图控制器添加一个导航控制器("mainViewController" 在代码片段中),这样您就可以 "push" 一个新的 table 到堆栈上。
我认为您应该使用基本 UIView 动画显示第一个 table
上 didSelectRowAtIndexPath 上从屏幕左侧移动的秒数 table
我有一个 UIViewController,其中包含连接在一起的地图和 tableView,它看起来像这样:
而且我希望能够将 tableView 推送到同一视图控制器中的另一个 tableView,以便地图保持原样。当然,我希望能够使用左上角导航栏中出现的按钮以编程方式向后展开 segue。
在放置在弹出窗口中的 iPad tableView 控制器中可以观察到类似的行为。我将如何在 Swift (iOS 8) 中执行此操作?
非常感谢任何代码片段或指向现有代码示例的指针。
这在技术上不是 "push" -- 当用户在您的 table 视图中选择一个单元格时,触发对 table 视图委托方法的调用
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
...您应该从屏幕右侧引入第二个 table 视图。
您的每个 table 视图数据源和委托方法都应该区分第一个和第二个 table 视图。这是 cellForRowAtIndexPath 的示例:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView1 {
return self.collection1.count
} else if tableView == self.tableView2 {
return self.collection2.count
}
return 0;
}
您可以像这样实现视图控制器包含:
- (void)viewDidLoad {
[super viewDidLoad];
// Setup the container view
_containerView = [[UIView alloc] initWithFrame: // DESIRED FRAME];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:_containerView];
// Setup the main view controller
[self addChildViewController:_mainViewController];
_mainViewController.view.frame = _containerView.bounds;
[_containerView addSubview:_mainViewController.view];
[_mainViewController didMoveToParentViewController:self];
}
现在您可以在单独的视图控制器中创建两个 table 视图。听起来您应该向主视图控制器添加一个导航控制器("mainViewController" 在代码片段中),这样您就可以 "push" 一个新的 table 到堆栈上。
我认为您应该使用基本 UIView 动画显示第一个 table
上 didSelectRowAtIndexPath 上从屏幕左侧移动的秒数 table