ios - 单击 Collection View 单元格时振动 iPhone 无法正常工作 Swift

标签 ios iphone swift

我有一个具有简单 UICollectionView 的应用程序

我只需要何时从此collectionView应用程序中选择任何单元格进行振动

这是我的代码

import AudioToolbox

ManualWaveCollectionView : UICollectionViewDataSource  , UICollectionViewDelegate , UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "locationsCell", for: indexPath) as! LocationCollectionViewCell
        let location = self.cellLocations[indexPath.row]
        cell.locationName.text = location.location
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.cellLocations.count
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
        AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))   
    }
}

没有发生任何事情,只是在点击collectionViewCell时保持打印()

我正在使用 Iphone 5s

最佳答案

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))  
}

关于ios - 单击 Collection View 单元格时振动 iPhone 无法正常工作 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47959826/

相关文章:

ios - 导航 Controller 标题未显示?

ios - 使用 Swift 隐藏取消隐藏静态 TableView 单元格

iOS/Swift - 使用 AWS3 (Amazon SDK) 将图像异步下载到 Collection View 中

iphone - 在不缩放叠加层的情况下缩放背景图像

iphone - 在 NSUserDefaults 中存储自定义对象的 NSArray

ios - BarChartView xAxis 标签不显示所有标签

ios - swift 2 : "Bool' is not convertible to 'BooleanLiteralConvertible'

ios - 如何*安全*地将 UITableView 滚动到一行?

ios - XCode 6.1 可能的索引错误?

iphone - 自定义表格单元格滚动