Answer the question
In order to leave comments, you need to log in
How to pass array from 1-ViewController to second one?
In general, I only start coding in swift, and after long reading of articles in English, I managed to transfer a variable from 1 VC to the second VC. But at the moment, I decided to pass an array of strings, but the compiler refuses to accept the array, and if you set , it compiles, but some other error.
Could not cast value of type '__NSDictionaryM' (0x102d6e8a8) to 'NSArray' (0x102d6e470).
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
let row = indexPath.row
if let navn = self.person[indexPath.row]["name"] as? NSString {
cell.textLabel?.text = navn as String
} else {
cell.textLabel?.text = "No Name"
}
return cell
}
//
// ViewController2.swift
// test2
//
// Created by Archakov on 01.09.15.
// Copyright (c) 2015 Archakov. All rights reserved.
//
import UIKit
class ViewController2: UIViewController {
var person: = [];
@IBOutlet weak var lbName: UILabel!
@IBOutlet weak var scroll: UIScrollView!
@IBAction func hidebutton(sender: AnyObject) {
//self.navigationController!.popToRootViewControllerAnimated(true)
}
override func viewDidLoad() {
super.viewDidLoad()
println(person[0][0]);
//let navn = self.person[0]["name"] as? [String]
//lbName.text = navn as String
scroll.contentSize.height = 500
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question