我想在swift中创建类似接口的功能,我的目标是当我调用另一个类时假设我正在调用API并且该类的响应我想反映到我当前的屏幕,在android界面中用来实现但应该是什么我在swift中使用它?任何人都可以帮我举个例子.android的代码如下:
public class ExecuteServerReq {
public GetResponse getResponse = null;
public void somemethod() {
getResponse.onResponse(Response);
}
public interface GetResponse {
void onResponse(String objects);
}
}
ExecuteServerReq executeServerReq = new ExecuteServerReq();
executeServerReq.getResponse = new ExecuteServerReq.GetResponse() {
@Override
public void onResponse(String objects) {
}
}
Run Code Online (Sandbox Code Playgroud) 使用Fetch API时,我试图捕获与同一原始策略相关的许多错误,但未成功:
window.onerror = (message, file, line, col, error) => console.log(error)
window.addEventListener('error', (error) => console.log(error))
try {
fetch('https://www.bitstamp.net/api/ticker/').catch(e => {
console.log('Caugth error:')
console.log(e)
console.log(JSON.stringify(e))
})
}
catch (e) {
console.log('try-catch')
console.log(e)
}
Run Code Online (Sandbox Code Playgroud)
我要捕获的错误仅出现在Web控制台中:
在此处查看代码示例:https : //github.com/nyg/fetch-error-test
如何捕获这些错误以提供屏幕消息?
编辑:实际执行获取的catch块。
window.onerror = (message, file, line, col, error) => console.log(error)
window.addEventListener('error', (error) => console.log(error))
try {
fetch('https://www.bitstamp.net/api/ticker/').catch(e => {
console.log('Caugth error:')
console.log(e)
console.log(JSON.stringify(e))
})
}
catch (e) {
console.log('try-catch')
console.log(e)
}
Run Code Online (Sandbox Code Playgroud)
fetch('https://www.bitstamp.net/api/ticker/')
.then(response => response.text())
.then(pre)
.catch(e => {
pre(`Caugth error: …Run Code Online (Sandbox Code Playgroud)我现在将此问题发布了更多次,但我还没有解决我的问题。在我的情况下,foregroundColor无法正常工作。即使深浅色未选择任何颜色,环也不会显示为深灰色。请查看我的代码并为我提供帮助。谢谢
import SVProgressHUD
//import SVProgressHud on top
SVProgressHUD.setDefaultStyle(.custom)
SVProgressHUD.setDefaultMaskType(.custom)
SVProgressHUD.setMinimumSize(CGSize(width: 60, height: 60))
SVProgressHUD.setRingThickness(3)
SVProgressHUD.setRingNoTextRadius(20)
SVProgressHUD.setBackgroundColor(UIColor.white)
SVProgressHUD.setForegroundColor(UIColor.darkGray)
SVProgressHUD.show()
Run Code Online (Sandbox Code Playgroud)
当我用2个会话测试我的应用程序时,在一个浏览器中所有的东西都可以,而在另一个浏览器中我得到了异常
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@PreserveOnRefresh
@SpringComponent
public class TestUI extends UI {
@Autowired
MainLayout content;
@Autowired
DetailView detailView;
@Override
protected void init(VaadinRequest request) {
VaadinSession.setCurrent(VaadinSession.getCurrent());
Navigator navigator = new Navigator(this, detailView);
navigator.addView("tests", TestView.class);
setContent(content);
}
}
Run Code Online (Sandbox Code Playgroud)
java.lang.IllegalStateException:未锁定会话时无法从父项中删除.此外,还有另一个锁定会话,表示该组件可能即将从一个会话移动到另一个会话.at com.vaadin.ui.AbstractSingleComponentContainer.removeFromParent(AbstractSingleComponentContainer.java:175)at com.vaadin.ui.AbstractSingleComponentContainer.setContent(AbstractSingleComponentContainer.java:148)at com.vaadin.ui.UI.setContent(UI.java:1312) )