Ios 对成员'的模糊引用;下标';在Xcode 8中
我搜索了关于成员“subscript”的模糊引用,但找不到任何解决方案。我正在使用TableView。这是我正在使用的代码:-Ios 对成员'的模糊引用;下标';在Xcode 8中,ios,swift3,xcode8,Ios,Swift3,Xcode8,我搜索了关于成员“subscript”的模糊引用,但找不到任何解决方案。我正在使用TableView。这是我正在使用的代码:- let people = [ ["Pankaj Negi" , "Rishikesh"], ["Neeraj Amoli" , "Dehradun"], ["Ajay" , "Delhi"] ]; // return the number of section func numberOfSections(in
let people = [
["Pankaj Negi" , "Rishikesh"],
["Neeraj Amoli" , "Dehradun"],
["Ajay" , "Delhi"]
];
// return the number of section
func numberOfSections(in tableView: UITableView) -> Int {
return 1;
}
// return how many row
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return people.count;
}
// what are the content of the cell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell();
var (personName , personLocation) = people[indexPath.row] // Ambiguous Reference to member 'subscript'
cell.textLabel?.text = personName;
return cell;
}
我是IOS开发新手,这就是为什么我很难理解这一点。但这段代码在Xcode 6中有效,但在Xcode 8中无效。为什么我不知道 不要认为相同的代码适用于您的Xcode 6,您在Xcode 6中所做的是创建了元组数组,但目前您正在创建2D数组,即每个数组元素都有一个带有两个字符串类型元素的数组 因此,将数组的声明更改为元组数组将删除该错误
let people = [
("Pankaj Negi" , "Rishikesh"),
("Neeraj Amoli" , "Dehradun"),
("Ajay" , "Delhi")
]
现在您将访问`cellForRowAt中的元组``
let (personName , personLocation) = people[indexPath.row]
cell.textLabel?.text = personName
注意:带Swift无需添加
若要指定语句结尾,它是可选的,除非您想在单行中添加连续语句谢谢,@Nirav D,我制作了2d数组,但我需要一个元组数组,在这种情况下,这就是它显示此错误的原因。从我的角度来看,用“[”代替“(”是一个愚蠢的错误。