协议未执行

时间:2018-08-22 11:45:06

标签: swift uiviewcontroller protocols

我正在尝试在整个应用程序中实现浅色和深色主题。我的问题是它无法正常工作。我有一个FATAL [mirrormaker-thread-0] Mirror maker thread failure due to (kafka.tools.MirrorMaker$MirrorMakerThread) java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.SslAuthenticationException: SSL handshake failed at org.apache.kafka.clients.producer.KafkaProducer$FutureFailure.<init>(KafkaProducer.java:1344) at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:969) at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:897) at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:774) at kafka.tools.MirrorMaker$MirrorMakerProducer.send(MirrorMaker.scala:709) at kafka.tools.MirrorMaker$MirrorMakerThread$$anonfun$run$6.apply(MirrorMaker.scala:431) at kafka.tools.MirrorMaker$MirrorMakerThread$$anonfun$run$6.apply(MirrorMaker.scala:431) at scala.collection.Iterator$class.foreach(Iterator.scala:891) at scala.collection.AbstractIterator.foreach(Iterator.scala:1334) at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) at scala.collection.AbstractIterable.foreach(Iterable.scala:54) at kafka.tools.MirrorMaker$MirrorMakerThread.run(MirrorMaker.scala:431) Caused by: org.apache.kafka.common.errors.SslAuthenticationException: SSL handshake failed Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1529) at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:535) at sun.security.ssl.SSLEngineImpl.writeAppRecord(SSLEngineImpl.java:1214) at sun.security.ssl.SSLEngineImpl.wrap(SSLEngineImpl.java:1186) at javax.net.ssl.SSLEngine.wrap(SSLEngine.java:469) at org.apache.kafka.common.network.SslTransportLayer.handshakeWrap(SslTransportLayer.java:435) at org.apache.kafka.common.network.SslTransportLayer.doHandshake(SslTransportLayer.java:301) at org.apache.kafka.common.network.SslTransportLayer.handshake(SslTransportLayer.java:255) at org.apache.kafka.common.network.KafkaChannel.prepare(KafkaChannel.java:79) at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:460) at org.apache.kafka.common.network.Selector.poll(Selector.java:398) at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:460) at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:239) at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:163) at java.lang.Thread.run(Thread.java:748) Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1728) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:330) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:322) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1614) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052) at sun.security.ssl.Handshaker$1.run(Handshaker.java:992) at sun.security.ssl.Handshaker$1.run(Handshaker.java:989) at java.security.AccessController.doPrivileged(Native Method) at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1467) at org.apache.kafka.common.network.SslTransportLayer.runDelegatedTasks(SslTransportLayer.java:389) at org.apache.kafka.common.network.SslTransportLayer.handshakeUnwrap(SslTransportLayer.java:469) at org.apache.kafka.common.network.SslTransportLayer.doHandshake(SslTransportLayer.java:328) ... 8 more Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:397) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:302) at sun.security.validator.Validator.validate(Validator.java:260) at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:281) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:136) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1601) ... 17 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392) ... 23 more [2018-08-20 04:30:07,862] FATAL [mirrormaker-thread-0] Mirror maker thread exited abnormally, stopping the whole mirror maker. (kafka.tools.MirrorMaker$MirrorMakerThread) ,其中包含2个ContainerVC-ContainerViewsSidebarMenuVCDashboardVC已偏移,因此最初显示的是用户SidebarMenuVC

DashboardVC嵌入在ContainerVC中,并且有一个汉堡包类型菜单。当用户点击该菜单按钮时,将显示UINavigationController。一切正常。

SidebarMenuVC包含负责更改应用程序主题的图像。当用户点击图像时,图像从亮变为暗,反之亦然。点击的瞬间会更改SidebarMenuVC的主题,但是当您隐藏菜单(通过滑动)时,SidebarMenuVC的主题不会被应用。我尝试使用DashboardVC来做到这一点,但我认为我做得不正确(嗯,它无法正常工作,所以我知道我已经搞砸了)。

protocol

因此,总体情况是:当用户向右滑动到protocol ReloadTheme { func reload() } class ContainerVC: UIViewController, SidebarDelegate { var delegateReloadTheme: ReloadTheme? func hideMenu() { sideBarMenuLeadingConstraint.constant = -300 applyTheme() animateConstraint() delegateReloadTheme?.reload() // when I put a breakpoint here, it shows it's nil } } extension DashboardVC : ReloadTheme { func reload() { applyTheme() } } (位于hideMenu()中时,它需要以某种方式访问​​ContainerVC并呼叫DashboardVC

协议/代表总是使我感到困惑,因此欢迎您提供一些帮助。

好的,根据要求,这是applyTheme()的连接方式:

sidebarMenu

然后在protocol SideBarDelegate: class { func showMenu() func hideMenu() } class DashboardVC: UIViewController { static weak var delegateSideBar: SideBarDelegate? @IBAction func sideMenuButtonPressed(_ sender: UIBarButtonItem) { Dashboard.delegateSideBar?.showMenu() } } 中:

ContainerVC

这就是滑动菜单的工作方式及其连接方式。

1 个答案:

答案 0 :(得分:1)

您需要将代表分配到某个地方-这是可选类型。

例如,在viewDidLoad中,您可以说item.delegateReloadTheme = self

您需要显示更多有关DashboardVC的代码。

基本上,当您创建委托时,您正在为需要委托的工作创建接口,并将其委托给其他类。因为您几乎可以在代码中的任何地方实现委托,所以您需要告诉谁负责实现该委托(接口)。

例如:

protocol RefresherDelegate {
    func refreshUI()
}

我们在这里定义将委托哪些函数。

class MyView : UIView {
    var delegate: RefresherDelegate?
}

在这里,我们创建一个变量,该变量将保存实际包含RefresherDelegate的对象。

class MyObject : RefresherDelegate {
    var myView = MyView()

您在这里说MyObject将实现RefresherDelegate并创建简单的MyView实例(不会在UI上显示,只是简单的示例)

func assignDelegate() {
    myView.delegate = self
}

这是至关重要的部分-将委托分配给它的实现-在这种情况下为MyObject

assignDelegate()之后,当您实际调用refreshUI()时,它将在MyObject中被调用。