我希望我的应用程序可以在每次用户需要时转到第一个视图控制器.
因此,我想创建一个函数来关闭所有视图控制器,无论它是在推送控制器中推送还是以模态方式呈现或打开任何方法.
我尝试了各种方法,但我当然没有解雇所有的视图控制器.有一个简单的方法吗?
let items: [String] = ["A", "B", "A", "C", "A", "D"]
items.whatFunction("A") // -> [0, 2, 4]
items.whatFunction("B") // -> [1]
Run Code Online (Sandbox Code Playgroud)
Swift 3是否支持这样的功能whatFunction(_: Element)
?
如果没有,最有效的逻辑是什么?
我很困惑,因为这只是一件简单的事情,但不起作用。
这是我在这里写问题之前的检查清单。
UICollectionViewDelegate 已注册
除了“调试视图层次结构”中的 UICollectionView 之外,没有任何内容
isUserInteractionEnabled
UICollectionView 和 UICollectionViewCell 是 true
isAllowsSelection
UICollectionView 是 true
还有什么我应该检查的吗?
======
class MyView: NibDesignable { // It's UIView with NibDesignableProtocol (https://github.com/mbogh/NibDesignable)
@IBOutlet weak var collectionView: UICollectionView!
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
private func setup() {
print("test - It's called.")
self.collectionView.dataSource = self
self.collectionView.delegate = self
self.collectionView.isUserInteractionEnabled = true
self.collectionView.isAllowsSelection = true
}
}
extension MyView: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func …
Run Code Online (Sandbox Code Playgroud) 我使用*.p8
APNs Auth Keys 而不是*.p12
证书来推送我的应用程序的通知。
而且,推送通知运行良好。
但是,我需要的与推送通知相关的第三方 SDK 只需要我提供*.pem
文件,而不需要*.p8
.
如果我只想*.p8
用于APNs,我现在不能使用这个SDK。这是正确的?
certificate pem push-notification apple-push-notifications ios
我猜这是与 相关的后台模式ExternalAccessory.framework
。
但是有关外部附件的文档说:“如果您的应用程序在附件通知到达时在后台暂停,则该通知将被放入队列中。当您的应用程序再次开始运行(无论是在前台还是后台)时,队列中的通知发送到您的应用程序。通知也会尽可能地合并和过滤,以消除任何不相关的事件。例如,如果在您的应用程序暂停时连接了配件并随后断开连接,您的应用程序最终将不会收到任何发生此类事件的指示.”。
这意味着外部配件通信将排队直到应用程序进入前台模式,但其他后台模式(如 )Location
在Bluetooth LE
后台模式下实时工作。所以我怀疑只是排队是唯一能做的事情。是不是真的?
首先,对我英语水平不足感到抱歉。
。
我想编写代码,如果单击.do-not-click-here
,请单击myFunction()
。
所以我写了下面的代码。
document.addEventListener('click', (event) => {
if(event.target.classList.includes('do-not-click-here')) {
myFunction();
}
)
Run Code Online (Sandbox Code Playgroud)
但是此代码返回错误“类型'EventTarget'上不存在属性'classList'。”
。
所以我尝试通过调试console.log
。
。
当我尝试 console.log(event);
event.target
作为javascript对象接收。(我要它)
。
当我尝试 console.log(event.target);
event.target
作为元素(?)接收。所以event.target.classList
不起作用。(也许)
。
如何获得event.target.classList
?
还是有比我想的更好的方法?
我想做一个像这个例子一样的函数。
例子
let num1 = Driver<Int>
let num2 = Driver<Int>
let result = Driver<String>
num1 = Observable.just(...).asDriver()
num2 = Observable.just(...).asDriver()
result = ??? // When both num1 and num2 are subscribed, this becomes a higher value among them as String.
// This type of code will be used
/*
if $0 >= $1 {
return "num1 = \($0)"
} else {
return "num2 = \($1)"
}
*/
Run Code Online (Sandbox Code Playgroud)
如何实施?
我做了一个能够切换自己的按钮,isEnabled
它正在根据这个状态更新按钮的标题和图像.
myButton.setTitle("Enabled Title", for: .normal)
myButton.setImage(UIImage(named: "enabled_resource_name"), for: .normal)
myButton.setTitle("Disabled Title", for: .disabled)
myButton.setImage(nil, for: .disabled)
Run Code Online (Sandbox Code Playgroud)
在isEnabled
我的按钮已经切换好.并且标题也根据那个改变了.但我发现了一个关于改变图像的奇怪问题.
在enabled
以disabled
情况下,图像UIImage(named: "enabled_resource_name")
也不会被删除.
但它改变了一点.当它被禁用时,图像变得有点透明.而在disabled
以enabled
情况下,做做工精细.
为什么会这样?
ios ×5
swift ×5
angular ×1
arrays ×1
certificate ×1
javascript ×1
navigation ×1
pem ×1
rx-swift ×1
swift3 ×1
swift4 ×1
typescript ×1
uibutton ×1