我有一个包含两个部分的表格。我可以在索引处选择行 - 但我无法区分各个部分。
该表是一个拉出菜单 - 仅在代码中创建。
选择的委托(delegate)方法是
func sideBarControlDidSelectRow(indexPath: NSIndexPath) {
delegate?.sideBarDidSelectButtonAtIndex(indexPath.row)
sectionis = indexPath.section
NSLog("Index Path Section %d", indexPath.section)
}
这给了我控制台中的部分。
但是在 View Controller 上我只有
func sideBarDidSelectButtonAtIndex(index: Int){
switch(index) {
etc.
}
}
我需要做的是类似
func sideBarDidSelectButtonAtIndex(index: Int){
if section == 0 {
switch(index){
etc.
}
}
}
但如果我尝试这样做,则二元运算符不能应用于类型部分的操作数
这一定是显而易见的事情,因为表格一直都有部分 - 但答案却在躲避我。
最佳答案
只需更新委托(delegate)协议(protocol)中方法 sideBarDidSelectButtonAtIndex
的声明以接受 NSIndexPath 值,更改:
func sideBarDidSelectButtonAtIndex(index: Int)
到
func sideBarDidSelectButtonAtIndex(indexPath: NSIndexPath)
那么你可以去掉这个方法
func sideBarControlDidSelectRow(indexPath: NSIndexPath) {
delegate?.sideBarDidSelectButtonAtIndex(indexPath.row)
}
并用
替换它的调用delegate?.sideBarDidSelectButtonAtIndex(indexPath)
然后你将收到完整的 indexPath 并可以做你想做的事
关于ios - 在不同部分的索引处选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30834882/