I have 2 view controllers, created separately. It's not navigation controller or other. I've 2 files for each of them: ViewController.swift
, SecondViewController.swift
. Second VC is called audioList
In 1-st VC I have a button and by clicking on it I'm opening second VC using code
dispatch_sync(dispatch_get_main_queue(), { () -> Void in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
self.presentViewController(controller, animated: true, completion: nil)
})
There is an array called music
in SecondViewController. I want to fill it with elements before code which you can see upper - from 1-st VC.
I've read this and that one post, others, read about doing it by creating protocol with function which changes data, tried a lot with segues, their performing and prepareFor-functions - but nothing worked.
Help me please with filling array in 2-nd VC
from button-click-action in 1-st VC
Update:
In SecondViewController.swift
I have this code:
var music: [String] = ["test"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return music.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell:UITableViewCell=UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell")
cell.textLabel!.text = music[indexPath.row]
return cell
}