我无法将当前周转换为secondviewcontroller。我的代码是这样的:
我的阵列:
var EUW = [("Week 1", "4 matches", "EUW"), ("Week 2", "4 matches", "EUW")]
var NA = [("Week 3" ,"4 matches", "NA"), ("Week 4", "4 matches", "NA")]
我的代码如下:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var secondscene = segue.destinationViewController as SecondViewController
if let indexPath = MyTable.indexPathForSelectedRow() {
let (currentweek,amountofmatches) = EUW[indexPath.row]
secondscene.match = currentweek
}
现在这段代码适用于第一部分,这很明显,因为我没有定义任何部分。因此,当我在secondviewcontroller中创建一个标签,说明它收到的那个星期它在第1周第1周的第1周,第2周第2周但在第2部分(NA部分)中说它在第3周第1周点击时说当点击第4周第2周时
但是当我尝试像这样定义第二部分时:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var secondscene = segue.destinationViewController as SecondViewController
if let indexPath = MyTable.indexPathForSelectedRow() {
if indexPath.section == 0 {
let (currentweek,amountofmatches) = EUW[indexPath.row]
} else { let (currentweek,amountofmatches) = NA[indexPath.row]
}
secondscene.match = currentweek
}
然后它说当前周是一个未解析的标识符,它不构建代码。
答案 0 :(得分:0)
看起来范围有问题。在最后一组代码中,您可以在currentweek
语句中定义if
:
let (currentweek,amountofmatches) = EUW[indexPath.row]
因此,在currentweek
语句之外无法访问if
变量。要解决此问题,您可以执行以下操作:
var (currentweek:String,amountofmatches:String);
if indexPath.section == 0 {
(currentweek,amountofmatches) = EUW[indexPath.row]
} else {
(currentweek,amountofmatches) = NA[indexPath.row]
}
secondscene.match = currentweek