我在使用可选绑定的SwiftUI时遇到了问题,基本上是macOS上的一个列表,一旦选择了某个项目,我就在其中添加一个DetailView,如果未选中,则添加一个文本。
当我打开应用程序时,它会很好,出现文本,然后添加一些项目并选择它,也可以正常工作,出现DetailView,但是一旦我在表格外单击并取消选择它,它就会崩溃。甚至很难,我有条件地检查是否为零,这就是为什么它第一次起作用的原因。
我猜DetailView保留了对selectedItem的引用,并将其设置为nil时崩溃,但是我认为一旦State属性更改,整个主体都应该刷新,这将从内存中删除以前的DetailView而不调用新的,对吧?
这是代码:
<img>
答案 0 :(得分:1)
我想DetailView保留了对selectedItem的引用,并且 设置为零时会崩溃,但我认为整个身体应该 更改State属性后刷新,这将删除 内存中的上一个DetailView而不调用新的,对吧?
未定义更新顺序,因此我在上面回答“否”。
这是一个解决方案。经过Xcode 11.4 / iOS 13.4的测试
[DEBUG] 2020-05-30 23:17:29.848 [http-nio-8090-exec-6] JdbcTransaction - [] Opening JDBC Connection
[DEBUG] 2020-05-30 23:17:30.336 [http-nio-8090-exec-6] JdbcTransaction - [] Setting autocommit to false on JDBC Connection [oracle.jdbc.driver.T4CConnection@c1d7134]
[DEBUG] 2020-05-30 23:17:30.336 [http-nio-8090-exec-6] getTotalUniqueUsersDetailsByKeyByTime - [] ==> Preparing: with main_data as ( select /*+ parallel(SCHUC) parallel(SCHU) parallel(SCHUT) parallel(SCHCM) parallel(SCHET) parallel(SCHES) */ distinct schutm.user_type_meta_name as KEY ,schuc.time_unit as TIME_UNIT ,schuc.user_key as VALUE from ( /* BP1 */ /* BP4 */ select /*+ parallel(SCHUCD) parallel(SCHFQL) */ YEAR_MONTH as TIME_UNIT ,schucd.TRACE_ID_KEY ,schucd.platform_id ,schucd.user_key ,schucd.event_type_id ,schucd.event_source_id ,REFERRER_ID ,PARENT_ID ,sum(USAGE_COUNT) as usage_count from sc_report_new.sc_hub_usage_counts_day schucd WHERE FISCAL_QUARTER_ID IN ( ? ) group by YEAR_MONTH ,schucd.TRACE_ID_KEY ,schucd.platform_id ,schucd.user_key ,schucd.event_type_id ,schucd.event_source_id ,REFERRER_ID ,PARENT_ID ) schuc inner join sc_hub_users schu on schuc.user_key=schu.user_key inner join sc_hub_user_types schut on schut.user_type_id=schu.user_type_id inner join sc_hub_user_types_meta_map schutmm on schutmm.user_type_id=schut.user_type_id inner join sc_hub_user_types_meta schutm ON schutm.user_type_meta_id = schutmm.user_type_meta_id inner join sc_hub_content_master schcm on schcm.trace_id_key=schuc.trace_id_key inner join sc_hub_event_types schet on schet.event_type_id = schuc.event_type_id inner join sc_hub_event_sources sches on sches.event_source_id = schuc.event_source_id WHERE ( (schcm.PAGETYPE='Page' AND sches.event_source_name='wem' AND schet.event_code='V') OR (schcm.PAGETYPE='Page' AND sches.event_source_name='purchaseshubs' AND schet.event_code='S') OR (schcm.PAGETYPE='Hub' AND sches.event_source_name='saleshubs' AND schet.event_code='S') ) ) select /*+parallel(AUTO) */ KEY,time_unit,count(VALUE) as VALUE from main_data group by KEY,TIME_UNIT order by case when KEY = 'Other' then 1 else 0 end, KEY, TIME_UNIT
[DEBUG] 2020-05-30 23:17:30.336 [http-nio-8090-exec-6] getTotalUniqueUsersDetailsByKeyByTime - [] ==> Parameters: 2020Q4(String)
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLRecoverableException: IO Error: Socket read timed out
### The error may exist in com/mycompany/myapp/screport/mapper/hubportfolio/TotalUniqueUsers.xml
### The error may involve com.mycompany.myapp.screport.mapper.hubportfolio.TotalUniqueUsers.getTotalUniqueUsersDetailsByKeyByTime-Inline
### The error occurred while setting parameters
### SQL: with main_data as ( select /*+ parallel(SCHUC) parallel(SCHU) parallel(SCHUT) parallel(SCHCM) parallel(SCHET) parallel(SCHES) */ distinct schutm.user_type_meta_name as KEY ,schuc.time_unit as TIME_UNIT ,schuc.user_key as VALUE from ( /* BP1 */ /* BP4 */ select /*+ parallel(SCHUCD) parallel(SCHFQL) */ YEAR_MONTH as TIME_UNIT ,schucd.TRACE_ID_KEY ,schucd.platform_id ,schucd.user_key ,schucd.event_type_id ,schucd.event_source_id ,REFERRER_ID ,PARENT_ID ,sum(USAGE_COUNT) as usage_count from sc_report_new.sc_hub_usage_counts_day schucd WHERE FISCAL_QUARTER_ID IN ( ? ) group by YEAR_MONTH ,schucd.TRACE_ID_KEY ,schucd.platform_id ,schucd.user_key ,schucd.event_type_id ,schucd.event_source_id ,REFERRER_ID ,PARENT_ID ) schuc inner join sc_hub_users schu on schuc.user_key=schu.user_key inner join sc_hub_user_types schut on schut.user_type_id=schu.user_type_id inner join sc_hub_user_types_meta_map schutmm on schutmm.user_type_id=schut.user_type_id inner join sc_hub_user_types_meta schutm ON schutm.user_type_meta_id = schutmm.user_type_meta_id inner join sc_hub_content_master schcm on schcm.trace_id_key=schuc.trace_id_key inner join sc_hub_event_types schet on schet.event_type_id = schuc.event_type_id inner join sc_hub_event_sources sches on sches.event_source_id = schuc.event_source_id WHERE ( (schcm.PAGETYPE='Page' AND sches.event_source_name='wem' AND schet.event_code='V') OR (schcm.PAGETYPE='Page' AND sches.event_source_name='purchaseshubs' AND schet.event_code='S') OR (schcm.PAGETYPE='Hub' AND sches.event_source_name='saleshubs' AND schet.event_code='S') ) ) select /*+parallel(AUTO) */ KEY,time_unit,count(VALUE) as VALUE from main_data group by KEY,TIME_UNIT order by case when KEY = 'Other' then 1 else 0 end, KEY, TIME_UNIT
### Cause: java.sql.SQLRecoverableException: IO Error: Socket read timed out
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
at com.mycompany.myapp.screport.dao.SCHubPortfolioServiceHandler.getTotalUniqueUserDetailsByTime(SCHubPortfolioServiceHandler.java:296)
at com.mycompany.myapp.screport.services.SCHubPortfolioService.getTotalUniqueUserDetailsByTime(SCHubPortfolioService.java:269)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:174)
at com.thetransactioncompany.cors.CORSFilter.doFilter(CORSFilter.java:237)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLRecoverableException: IO Error: Socket read timed out
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:897)