ビューコントローラには2つの関数があります。最初の関数はJSONを解析して配列を作成します。別の配列は配列データを持つテーブルを生成します。問題は、最初の関数が配列データを2番目の関数に送ることができないように見えることです。ここでSwiftで変数が1つの2つの関数
はコードです: -
class secondViewController: UIViewController, UITableViewDataSource {
let chartTitle:[String] = ["Name",......]
func parseJSON(){
let url = NSURL(string: "http://00000.us-west-2.elasticbeanstalk.com/index.php?000000")
let request = NSURLRequest(URL: url!)
do {
let data = try NSURLConnection.sendSynchronousRequest(request, returningResponse: nil)
do {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers)
var name = json["Name"]
var chartContent:[String] = ["\(name)",.....] //Contents of current chart contents
} catch{
//Handle Exception
}
} catch{
//Handle Exception
}
}
override func viewDidLoad() {
parseJSON()
...
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { //currnet table information.
let cell = UITableViewCell()
cell.textLabel?.text = chartTitle[indexPath.row] + "\t\t\t\t\t here comes info" + chartContent[indexPath.row]
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return chartTitle.count
}
}
このコードはtableView
機能にエラーがあります。未解決の識別子の
使用すると、 'chartContent'
私は宣言してみました最初の関数の外の変数はクラスsecondViewController
のすぐ下ですが、に別のエラーがありました。
これらのソリューションはありますか?