xcode-具有多个标识符的prepareForSegue
我有一个包含两个部分的tableView(不是静态单元格) 一个酒吧区和一个俱乐部区(每个都有几个单元)。我希望同一部分的每个单元格都指向同一个viewcontroller 我只能进入第一个,永远不能进入最后一个。即使是第二部分中的de单元也会转到第一个viewcontrollerxcode-具有多个标识符的prepareForSegue,xcode,swift,segue,identifier,Xcode,Swift,Segue,Identifier,我有一个包含两个部分的tableView(不是静态单元格) 一个酒吧区和一个俱乐部区(每个都有几个单元)。我希望同一部分的每个单元格都指向同一个viewcontroller 我只能进入第一个,永远不能进入最后一个。即使是第二部分中的de单元也会转到第一个viewcontroller override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "ba
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "barSegue"{
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedBar = self.areas.bars[selectedIndex.row]
let detailBarViewController = segue.destinationViewController as! DetailBarViewController
detailBarsViewController.bars = selectedBar
}
else if segue.identifier = "clubSegue" {
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedClub = self.areas.clubs[selectedIndex.row]
let detailClubViewController = segue.destinationViewController as! DetailClubViewController
detailClubsViewController.clubs = selectedClub
}
}
有人能看出我的错误吗
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
if section == 0 {
return areas.bars.count
} else {
return areas.clubs.count
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("mainIdentifier", forIndexPath: indexPath)
if indexPath.section == 0 {
let bars = areas.bars
let bar = bars[indexPath.row]
cell.textLabel?.text = bar.name
return cell
} else {
let clubs = areas.clubs
let club = clubs[indexPath.row]
cell.textLabel?.text = club.name
return cell
}
}
赛格:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "barsandclubsIdentifier"{
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedBar = self.areas.bars[selectedIndex.row]
let detailBarsAndClubsViewController = segue.destinationViewController as! DetailBarOrClubViewController
detailBarsAndClubsViewController.bars = selectedBar
}
else {
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedClub = self.areas.clubs[selectedIndex.row]
let detailBarsAndClubsTwoViewController = segue.destinationViewController as! DetailBarOrClubTwoViewController
detailBarsAndClubsTwoViewController.clubs = selectedClub
}
每个原型单元只能转换为单个viewController。如果有2个不同的目标ViewController,则需要2个原型单元格:1个用于酒吧,1个用于俱乐部。给他们每个人一个唯一的标识符,例如
“barCell”
和“clubCell”
然后在单元格中为rowatinexpath
,将适当的单元格出列:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellID = ["barCell", "clubCell"][indexPath.section]
let cell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath)
然后可以将每个原型单元连接到相应的viewController。为这两个序列中的每一个赋予唯一标识符,例如“barSegue”
和“clubSegue”
,然后您可以使用prepareForSegue
中的标识符来配置目标viewController
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "barSegue"{
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedBar = self.areas.bars[selectedIndex.row]
let detailBarViewController = segue.destinationViewController as! DetailBarViewController
detailBarsViewController.bars = selectedBar
}
else if segue.identifier = "clubSegue" {
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedClub = self.areas.clubs[selectedIndex.row]
let detailClubViewController = segue.destinationViewController as! DetailClubViewController
detailClubsViewController.clubs = selectedClub
}
}
每个原型单元只能转换为单个viewController。如果有2个不同的目标ViewController,则需要2个原型单元格:1个用于酒吧,1个用于俱乐部。给他们每个人一个唯一的标识符,例如
“barCell”
和“clubCell”
然后在单元格中为rowatinexpath
,将适当的单元格出列:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellID = ["barCell", "clubCell"][indexPath.section]
let cell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath)
然后可以将每个原型单元连接到相应的viewController。为这两个序列中的每一个赋予唯一标识符,例如“barSegue”
和“clubSegue”
,然后您可以使用prepareForSegue
中的标识符来配置目标viewController
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "barSegue"{
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedBar = self.areas.bars[selectedIndex.row]
let detailBarViewController = segue.destinationViewController as! DetailBarViewController
detailBarsViewController.bars = selectedBar
}
else if segue.identifier = "clubSegue" {
let selectedIndex = self.tableView.indexPathForSelectedRow!
let selectedClub = self.areas.clubs[selectedIndex.row]
let detailClubViewController = segue.destinationViewController as! DetailClubViewController
detailClubsViewController.clubs = selectedClub
}
}
单击单元格时会发生什么情况?节0中的单元格将转到DetailBarOrClubViewController,而节中的单元格需要转到另一个。现在他们都去了DetailBarOrClubViewController。你的故事板中有多少动态原型单元?如果你对两个部分重复使用同一个单元格,它只会切换到其中一个视图控制器。那就是PetahChristian!!!万分感谢!!我真蠢:p单击单元格时会发生什么?第0节中的单元格将转到DetailBarOrClubViewController,而第0节中的单元格需要转到另一个。现在他们都去了DetailBarOrClubViewController。你的故事板中有多少动态原型单元?如果你对两个部分重复使用同一个单元格,它只会切换到其中一个视图控制器。那就是PetahChristian!!!万分感谢!!我真蠢:p