如何将UIEvent对象复制到本地数据结构?

时间:2019-05-20 18:06:15

标签: swift copy uievent

下面是一段代码:

import UIKit
import RxCocoa
import RxSwift
import FTPopOverMenu_Swift

public let popoverShowLists: PublishSubject<([List], UIEvent?)> = PublishSubject<([List], UIEvent?)>()

private func setupPopoverShowList() {
    popoverShowLists
        .subscribe(onNext: { lists, event in
            if let event = event {
                let cellConfi = FTCellConfiguration()
                cellConfi.textFont = UIFont.systemFont(ofSize: 18)
                var cellConfis = Array(repeating: cellConfi, count: lists.count)
                FTPopOverMenu.showForEvent(event: event, with: lists.map{ $0.name }, menuImageArray: nil, cellConfigurationArray: cellConfis, done: { selectedIndex in
                    print(selectedIndex)
                }, cancel: {})
            }
        }).disposed(by: disposeBag)
}

public func getListOfLists(event: UIEvent?) {
    print(event) // First Print event
    URLRequest.loadRequestGET(resource: APIManager.getAllLists, tokenUser: User.token!)
        .subscribe(onNext: { [weak self] response, result, error in
            print(event) // Second Print event
            switch response.statusCode {
            case HTTPStatusCodes.OK.rawValue:
                if let result = result {
                    self?.popoverShowLists.onNext((result.list, event))
                }
            case HTTPStatusCodes.BadRequest.rawValue:
                if let error = error { print("[-] Error[\(error.opcode)] \(error.message)") }
            default:
                break
            }
        }).disposed(by: disposeBag)
}

@IBAction func selectListButtonAction(_ sender: UIBarButtonItem, event: UIEvent) {
    getListOfLists(event: event)
}

我试图显示一个带有我的请求响应内容的弹出窗口,这是一个简单的字符串列表。 FTPopoverMenu需要参数中的事件。不幸的是,执行请求后,我失去了事件的价值,所以我的弹出窗口没有显示。

活动的第一张照片:

Optional(<UITouchesEvent: 0x600002b8c6c0> timestamp: 196495 touches: {(
    <UITouch: 0x7f8401715f10> phase: Ended tap count: 1 force: 0.000 window: <UIWindow: 0x7f8401516b60; frame = (0 0; 1024 768); gestureRecognizers = <NSArray: 0x6000017e0d50>; layer = <UIWindowLayer: 0x6000019ec580>> view: <_UIButtonBarButton: 0x7f8401617120; frame = (0 0; 49 44); tintColor = UIExtendedSRGBColorSpace 0.156794 0.261571 0.36564 1; layer = <CALayer: 0x6000019d7a60>> location in window: {31.5, 43} previous location in window: {31.5, 43} location in view: {19.5, 20} previous location in view: {19.5, 20}
)})

活动的第二张照片:

Optional(<UITouchesEvent: 0x600002b8c6c0> timestamp: 196495 touches: {(
)})

我该如何解决?谢谢:)

0 个答案:

没有答案