我正在浏览这个appcoda blog并遇到了一个函数,我必须得到可见行的索引。我正在学习并实施Swift 3
/ Xcode 8
。我的以下函数出现No subscript members
错误。
func getIndicesOfVisibleRows() {
visibleRowsPerSection.removeAll()
for currentSectionCells in cellDescriptors {
var visibleRows = [Int]()
for row in 0...((currentSectionCells as! [[String: AnyObject]]).count - 1) {
if currentSectionCells[row]["isVisible"] as! Bool == true { //Get compile time error here
visibleRows.append(row)
}
}
visibleRowsPerSection.append(visibleRows)
}
}
如何获取currentSectionCells
数组的对象,其键的对象为" isVisible
"这里吗?
答案 0 :(得分:3)
您需要像这样向cellDescriptors
指定数组[[[String:Any]]]
的类型。
for currentSectionCells in cellDescriptors.objectEnumerator().allObjects as! [[[String:Any]]]{
var visibleRows = [Int]()
for row in 0..<currentSectionCells.count {
if currentSectionCells[row]["isVisible"] as! Bool == true {
visibleRows.append(row)
}
}
visibleRowsPerSection.append(visibleRows)
}
答案 1 :(得分:0)
试试这个:
item
和
Check()
答案 2 :(得分:0)
func getIndicesOfVisibleRows(){ visibleRowsPerSection.removeAll()
for currentSectionCells in cellDescriptors {
print(currentSectionCells)
var visibleRows = [Int]()
for row in 0...((currentSectionCells as AnyObject).count - 1) {
if (currentSectionCells as AnyObject).objectAt(row)["isVisible"] as! Bool == true {
visibleRows.append(row)
}
}
visibleRowsPerSection.append(visibleRows)
}
}
答案 3 :(得分:0)
您可以做的另一件事是,将您的cellDescriptors创建为特定的swift数组,如下所示。
$path = $db->givePath($service);
if(exec("cmd /c" . $path)){
echo "Successful sent";
} else {
echo "Error";
}
并从.plist文件加载您的cellDescriptor,如下所示。
var cellDescriptors: [[[String: Any]]]!
现在,您的代码(问题提到)将按原样运行,不做任何更改!