我无法将从mapKit注释执行segue 到另一个故事板上的其他视图控制器。
我有一个带有全屏地图视图的故事板,我想对包含PanelViewController的其他故事板执行segue。
使用console.log('App.js is running');
const app = {
title: 'Decision',
subtitle: 'For binary life decisions, put your trust in a computer',
options: []
};
const onFormSubmit = e => {
e.preventDefault();
const option = e.target.elements.option.value;
if (option) {
app.options.push(option);
e.target.elements.option.value = '';
render();
}
};
const onRemoveAll = () => {
app.options = [];
render();
};
// create "Remove All" button above list
// on click -> wipe the array -> rerender
const appRoot = document.getElementById('app');
const numbers = [55, 101, 1000];
const render = () => {
const template = (
<div>
<h1>{app.title}</h1>
{app.subtitle && <p>{app.subtitle}</p>}
<p>{app.options.length > 0 ? 'Here are your options' : 'No options'}</p>
<p>{app.options.length}</p>
<button onClick={onRemoveAll}>Remove All</button>
{
[99, 98, 97]
}
<ol>
<li>Item one</li>
<li>Item two</li>
</ol>
<form onSubmit={onFormSubmit}>
<input type="text" name="option" />
<button>Add Option</button>
</form>
</div>
);
ReactDOM.render(template, appRoot);
};
render();
将MKAnnotation添加到地图后,我使用map.addAnnotation()
来获取当前选定的标记。我知道我必须在这里执行segue,但我不知道如何。
我想我有 2个选项,但它们都不起作用:
present(PanelViewController,animated:true,completion:nil)
这给了我一个错误:“mapView(_:didSelect:)
”
performSegue(withIdentifier:“showPanel”,sender:view)
这会导致应用程序因未捕获的异常错误而崩溃:“Cannot convert value of type 'PanelViewController.Type' to expected argument type 'UIViewController'
”
当然这是真的,因为我在这个视图控制器上没有带有此标识符的segue。我不知道我将如何创建一个,因为它只是一个全屏mapKit视图,xcode不允许我从mapKit视图中拖放到另一个视图控制器。
有什么想法吗?
答案 0 :(得分:0)
此
present(PanelViewController, animated: true, completion: nil)
应为实例,为IB中的VC PanelViewController
创建名为 nextID 的storyborad id
let stoBr = UIStoryboard(name: "nameOfSB", bundle: nil)
let next = stoBr.instantiateViewController(withIdentifier: "nextID") as! PanelViewController
// here configuew next properties
present(next, animated: true, completion: nil)
和这个
performSegue(withIdentifier: "showPanel", sender: view)
你做的当前VC必须有一个名为 showPanel 的segue到目的地VC