prepareForSegue (ViewController)

298 views Asked by At

Then i try to sent data from one view to another

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "varView" {
        var viewController = segue.destinationViewController as ViewController

        var indexPath = self.tableView.indexPathForSelectedRow()

        viewController.varView = self.exams[indexPath.row]

    }

}

I get an error at witch says that ViewController is a undeclared?

1

There are 1 answers

0
objectiveCoder On BEST ANSWER

Rather than prepareForSegue you can directly call viewController from storyboard and pass the data

declare variable in the file you want to pass the data and #import the header file in which you want to pass the data.

#import "file.h"

file *data = [[file alloc]init];
data.index = add_index;

then navigate as follow...

UINavigationController *navigationController = (UINavigationController *)self.navigationController;
UIViewController *createEvent = [self.storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerID"];

[navigationController pushViewController:createEvent animated:YES];