iOS ReactorKit单元选择无法正常工作

时间:2018-09-30 03:53:40

标签: uicollectionview rx-swift multipleselection reactor

我正在使用WINDOW TUMBLING (SIZE 1 minutes) 2018-09-30 11:32:00 WINDOW TUMBLING (SIZE 2 hours) 2018-09-30 10:00:00 WINDOW TUMBLING (SIZE 5 hours) 2018-09-30 07:00:00 WINDOW TUMBLING (SIZE 10 hours) 2018-09-30 02:00:00 WINDOW TUMBLING (SIZE 11 hours) 2018-09-30 07:00:00 WINDOW TUMBLING (SIZE 12 hours) 2018-09-30 08:00:00 WINDOW TUMBLING (SIZE 24 hours) 2018-09-30 08:00:00 uicollectionView

建立共享功能

我的设置是

PhotoListViewReactor.class

ReactorKit

class PhotoListViewReactor : Reactor { enum Action { case shareInit case select(photo: Photo) case deselect(photo: Photo) case shareConfirm case shareFinish } enum Mutation { case selectShare(_ photo: Photo) case deselectShare(_ photo: Photo) case setSharingState(Bool) case triggerShareAction case shareComplete } struct State { var sharePhotos: [Photo] = [] var isSharing: Bool = false var shareAction: Bool = false } var initialState = State() // init() { } func mutate(action: Action) -> Observable<Mutation> { switch action { case .select(photo: let photo): return Observable.just(Mutation.selectShare(photo)).takeUntil(self.action.filter(isSharingAction)) case .deselect(photo: let photo): return Observable.just(Mutation.deselectShare(photo)).takeUntil(self.action.filter(isSharingAction)) case .shareInit: return Observable.just(Mutation.setSharingState(true)) case .shareConfirm: return Observable.concat([Observable.just(Mutation.triggerShareAction), Observable.just(Mutation.setSharingState(false))]) case .shareFinish: return Observable.concat([Observable.just(Mutation.shareComplete),Observable.just(Mutation.setSharingState(false))]) } } func reduce(state: State, mutation: Mutation) -> State { switch mutation { case let .selectShare(photo): var newState = state newState.sharePhotos.append(photo) return newState case let .deselectShare(photo): var newState = state newState.sharePhotos.removeAll(where: { $0.id == photo.id }) return newState case let .setSharingState(isSharing): var newState = state newState.isSharing = isSharing return newState case .triggerShareAction: var newState = state newState.shareAction = true return newState case .shareComplete: var newState = state newState.shareAction = false newState.isSharing = false newState.sharePhotos = [] return newState } } private func isSharingAction(_ action: Action) -> Bool { if case .shareInit = action { return true } else { return false } } }

PhotoListViewController

要清除我的过滤器如果运算符:

    self.collectionView.rx.modelSelected(Photo.self).share()
        .filter(if: reactor.state.map{$0.isSharing})
        .map {Reactor.Action.select(photo: $0)}
        .bind(to: reactor.action)
        .disposed(by: disposeBag)


    self.collectionView.rx.modelDeselected(Photo.self).share()
        .filter(if: reactor.state.map{$0.isSharing})
        .map {Reactor.Action.deselect(photo: $0)}
        .bind(to: reactor.action)
        .disposed(by: disposeBag)

我的问题是选择和取消选择不能正常工作(选择后,用户无法再次单击以取消选择单元格)。我在uicollectionview中启用了多节。

1 个答案:

答案 0 :(得分:0)

您必须使用find_difference的{​​{1}}和def assign_clusters_to_samples(data, clusters): # clusters-array of clusters, sample-single sample from the database def euclidean_distances(clusters, sample): distances = np.sum((clusters - sample)**2, axis=1) # return index with the minimal distance return np.where(distances==np.min(distances))[0] return [euclidean_distances(clusters, sample) for sample in data] API。在使用UICollectionView选择索引路径之前,selectItem(at:animated:scrollPosition:)不会发出任何值。