1
나는 TableViewController
및 ViewController
입니다. 나는이 둘을 연결하고 어떤 행이 TableViewControler
에 탭으로 표시되었는지에 따라 특정 문을 ViewController
에 인쇄하려고합니다.Swift : if 문의 예상 선언 오류
rowCounter
이라는 공용 변수를 선언했고 TableViewController
클래스에서 나는 rowCounter
을 indexPath
의 행과 동일하게 설정했습니다.
TableViewController
그 다음 rowCounter
변수에 액세스하고 숫자에 의존하는 문을 인쇄하기 위해 if 문을 사용하려고하지만 '예상 선언'오류가 계속 발생합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
TableViewController
:
import UIKit
var rowCounter: Int = 0
class TableTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
rowCounter = indexPath.row
return indexPath
}
ViewController
: 여기
import UIKit
class ViewController: UIViewController {
if rowCounter == 1 {
println("test")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}