用Swift实现一个TableView,列表上调用LeanCloud的数据。

如图所示,因为我存储的全部都是label,所以运行下面的代码之后直接可以显示到主列表当中:



那么,首先 我们需要在你的主视图控制器中,修改下面的代码:

   func numberOfSectionsInTableView(tableView: UITableView) -> Int {

        // #warning Incomplete implementation, return the number of sections

        return 1

    }


   func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        // #warning Incomplete implementation, return the number of rows

        return todos.count

    }


接下来,为了连接上LeanCloud,你需要查看LeanCloud上的文档.然后显示到每个cell上面:

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        print("当前数据行=\(indexPath.row)")

        //读取视图中的cell

        let cell :PasswordCell = tableView.dequeueReusableCellWithIdentifier("pass_word_cell", forIndexPath: indexPath) as! PasswordCell

        //获取数组的当前值

        let this_password = self.todos[indexPath.row]

        //获取数组中存储的字段值

        let user_name: LCString! = this_password.get("user_name_field")

        let user_account: LCString! = this_password.get("user_account")

        let user_password: LCString! = this_password.get("user_password")

        let user_type: LCString! = this_password.get("user_type")

        //显示到cell

        cell.Username_label.text = "Username\(user_name.value)"

        cell.Account_label.text = "Account \(user_account.value)"

        cell.Password_label.text = "Password:  ******"

        cell.Type_label.text = "Type\(user_type.value)"


        return cell

    }





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值