12月 28

raspberry pi2 连接蓝牙键盘

B.O.W航世 无线蓝牙键盘 + raspberry pi 2 + 迷你USB蓝牙4.0适配器 无线接收器 CSR稳定芯片
CSR4.0
安装蓝牙程序
apt-get install -y bluetooth bluez-* blueman

使用命令lsusb,看看有没有识别usb蓝牙模块。我的信息如下:
Bus 001 Device 004: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)

重启操作系统或用命令开启蓝牙服务。
#/etc/init.d/bluetooth start

开启键盘蓝牙扫描,使用“hcitool scan”命令搜索到键盘。我的信息如下:
87:73:00:00:65:62 Bluetooth 3.0 Keyboard

开始在界面测试多次,都是4位配对码,总是失败。
在管理员模式下使用buletoothctl命令行进行连接操作。
# bluetoothctl
进入命令行控制台
[bluetooth]# power on // Power on the Bluetooth device
[bluetooth]# agent on // Start the agent
[bluetooth]# default-agent // Set agent as the default one
[bluetooth]# pairable on // Allow pairing
[bluetooth]# scan on // Enable scan so discoverable devices will be displayed
[bluetooth]# pair 87:73:00:00:65:62 // Pair with a discovered device
[bluetooth]# connect 87:73:00:00:65:62

根据提示,输入6位配对码。连接成功,键盘可用。
重启自动加载,编辑/etc/rc.local增加下面命令即可。
bluetoothctl connect 87:73:00:00:65:62

raspberrypi-bluekey

参考:
https://wiki.tizen.org/wiki/Bluetooth

12月 02

swift2 tableview 滑动删除

部分主要代码

    @IBOutlet weak var userTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        //注册缓存标示
        refreshControl.addTarget(self, action: "refreshData", forControlEvents: UIControlEvents.ValueChanged)
        refreshControl.attributedTitle = NSAttributedString(string: "松手刷新数据")
        userTableView.addSubview(refreshControl)
        refreshData()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func loadView() {
        super.loadView()
    }
    
    //在本例中,只有一个分区
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1;
    }

    // 删除部分开始
    //滑动删除必须实现的方法
    func tableView(tableView: UITableView,commitEditingStyle editingStyle: UITableViewCellEditingStyle,
        forRowAtIndexPath indexPath: NSIndexPath) {
            let index = indexPath.row
            self.dataArray.removeAtIndex(index)
            self.userTableView.deleteRowsAtIndexPaths([indexPath],
                withRowAnimation: UITableViewRowAnimation.Top)
    }
    
    //滑动删除
    func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath)
        -> UITableViewCellEditingStyle {
            return UITableViewCellEditingStyle.Delete
    }
    
    //修改删除按钮的文字
    func tableView(tableView: UITableView,
        titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
            return "删除"
    }
    //删除部分结束