A
A
Archakov Dennis2015-09-03 11:40:52
Swift
Archakov Dennis, 2015-09-03 11:40:52

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).

VC1:
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
        
    }

VC2:
//
//  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

1 answer(s)
P
Petrushka, 2015-09-03
@petruska

in the code, create a new controller,
set how to property the desired array (in the new controller, it will be property with the received array)
go to it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question