prepareForSegue(ViewController)

时间:2015-06-09 12:51:16

标签: ios swift undefined viewcontroller

然后我尝试将数据从一个视图发送到另一个视图

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]

    }

}

我在女巫那里得到一个错误,说ViewController是未声明的?

1 个答案:

答案 0 :(得分:0)

而不是prepareForSegue您可以直接从故事板调用viewController并传递数据

在要传递数据的文件中声明变量,在#import声明要传递数据的头文件。

#import "file.h"

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

然后导航如下...

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

[navigationController pushViewController:createEvent animated:YES];