如图所示,因为我存储的全部都是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
}