我以为我会用swift构建一个ipad应用程序。我正在使用的应用程序是一个主 - 细节应用程序。在主表中,我有两行: “Window1”和“Window2”以及两个详细视图。我为两个细节视图创建了一个故事板segue(1是默认视图)。这两个段落被称为“showDetail”和“showWindow2”。在主从应用程序中使用Swift,我如何以编程方式切换细节视图?
视频我在YouTube上观看用下面的代码从主选项卡的用户引导到适当的详细页面:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
var row = indexPath.row
switch row
{
case 1:
self.performSegueWithIdentifier("showDetail", sender: self)
default:
self.performSegueWithIdentifier("showWindow2", sender: self)
}
}
其工作时,我有在母版页只有两排。 上面的代码似乎并不当我有母版页上3行工作(通过添加一行标签“Window3”):
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
var row = indexPath.row
switch row
{
case 1:
self.performSegueWithIdentifier("showDetail", sender: self)
case 2:
self.performSegueWithIdentifier("showWindow2", sender: self)
default:
self.performSegueWithIdentifier("showWindow2", sender: self)
}
}
我想我遇到的问题是,值的“行”似乎改变取决于我目前在哪一行。我的意思是当我调试时,选择“Window1”,“Window2”或“Window3”时的行值似乎在0,1和2之间变化,并且我的代码不会显示正确的详细信息页面。
我不知道我在这里错过了什么。任何人都可以请帮我吗?
我看到您正在使用'didDeselectRowAtIndexPath'。你是不是指'didSelectRowAtIndexPath'? – marosoaie 2015-04-06 08:56:58
Segue标识符与window2&window3相同。对于window3你也想显示window2的细节?你的意思是didSelectRowAtIndexPath? – 2015-04-06 08:59:30
谢谢你。当弹出自动填充窗口时,我选择了错误的方法....我的意思是使用didSelectRowAtIndexPath修复了我的问题。 – Woody 2015-04-06 13:22:54