我正在使用Template.displayResults.helpers({
projectsPossible: function () {
var utilitiesCheckedDB = Utilities.find({
checked: true
}).fetch();
var projectsAll = Projects.find().fetch();
return projectsPossible(utilitiesCheckedDB, projectsAll);
}
});
// Returns an array of all possible projects depending on the selected utilities
function projectsPossible(utilitiesCheckedDB, projectsAll) {
var result = [];
_.each(projectsAll, function (project) {
if (project.utilities.length === _.intersection(project.utilities, checkedCheckboxesList(utilitiesCheckedDB)).length) {
result.push(project);
}
});
return result;
}
// Returns an array of all checked utilities in the current checkbox database
function checkedCheckboxesList(checkedCheckboxesDB) {
var result = [];
_.each(checkedCheckboxesDB, function (checkbox) {
result.push(checkbox.name);
});
return result;
}
并希望推动视图控制器,以便在点击标签栏项目时显示在Storyboard
中。
为此,我使用与UITabBarController
上创建的ViewController
关联的现有TabBarController
并使用以下代码。但是,我得到例外, Storyboard不包含带标识符的视图控制器' SwitchViewController'
Storyboard
更新:我在func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
let switchViewController = self.storyboard?.instantiateViewControllerWithIdentifier("SwitchViewController")
self.presentViewController(switchViewController, animated: true, completion: nil)
return false
}
中为Storyboard ID
添加了SwitchViewController
,并对上述代码进行了评论。当我移动到此选项卡时,应用程序失败并出现相同的错误
我正在使用iOS 8和Xcode 7.请帮助
答案 0 :(得分:2)
检查您的故事板ID,
试试这个,
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
if viewController is SwitchViewController {
let switchViewController = self.storyboard?.instantiateViewControllerWithIdentifier("SwitchViewController") as! SwitchViewController
self.presentViewController(switchViewController, animated: true, completion: nil)
return false
}
return true
}
答案 1 :(得分:0)
请尝试以下代码: 让storyboard = UIStoryboard(名称:" Main",bundle:nil) 让VC = storyboard.instantiateViewControllerWithIdentifier(" SwitchViewController")