我有一个标签栏 Controller 设置。当用户选择一个选项卡时,会将他们带到 UIViewController
。目前我在这个 View Controller 中有一个 UITableView
设置。我想要做的是,在从 TableView1 中选择一个单元格后,我希望在 TableView2 从屏幕右侧进入并接管时产生“推”效果。
我发现了以下问题,与我的类似: UITableView segue within the same ViewController
其中一个建议正是我想要实现的,但是我无法让它具有那种幻灯片效果。
我所做的是添加两个 UITableViews
,然后在 viewDidLoad 中添加 tableView1.hidden = true
。
然后在代码中:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell: UITableViewCell!
if tableView == tableView1
{
// Dequeue the cell to load data
cell = tableView.dequeueReusableCellWithIdentifier("ID1", forIndexPath: indexPath)
....
}
else if tableView == tableView2
{
// Dequeue the cell to load data
cell = tableView.dequeueReusableCellWithIdentifier("ID2", forIndexPath: indexPath)
....
}
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
if tableView == tableView1
{
tableView2.hidden = false
tableView1.hidden = true
playlistVideosTableView.reloadData()
// Deselects the row
tableView1.deselectRowAtIndexPath(indexPath, animated: true)
}
}
但是,它没有那种“滑动效果”并且使 tableview 立即出现。
我可以用第二个 tableview 创建另一个 UIViewController
,但我不想让我的标签栏消失。
我怎样才能做到这一点,我怎样才能确保返回到第一个 UITableView?
谢谢
最佳答案
我建议简单地创建另一个具有 UITableView 的 UIViewController,因此最好是 UITableViewController。
然后在 tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
中调用新 ViewController 的 segue。这将为您提供所需的效果,同时也是一种更清洁的解决方案。
如果您将此选项卡中的所有 ViewController 嵌入到 NavigationController 中,则使用此解决方案也不会丢失您的 TabBar。
编辑:示例代码
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("editSpecialStage", sender: tableView.cellForRowAtIndexPath(indexPath))
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let indexPath = self.tableView.indexPathForCell(sender as! UITableViewCell)!
let secondViewController = segue.destinationViewController as! SecondViewController
}
在 Storyboard 中,您有一个 NavigationController 作为 TabBar 的第一个 ViewController。然后是第一个 ViewController,然后是第二个,通过 push segue 连接。
关于ios - 如何在同一个 ViewController 中推送到不同的 UITableView 并导航回第一个 UITableView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35523719/