【发布时间】:2018-10-26 23:42:59
【问题描述】:
这是我的问题。我有一个用户数组,我正在检查用户电话号码是否在地址簿中,我想在 tableView 中显示用户。
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return users.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! UserCell
let user = users[indexPath.row]
let contact = searchForContactUsingPhoneNumber(phoneNumber: user.phoneNumber!)
if contact == true {
cell.textLabel?.text = user.name
cell.detailTextLabel?.text = user.phoneNumber
cell.backgroundColor = UIColor(r: 35, g: 35, b: 35)
cell.textLabel?.textColor = UIColor.white
cell.detailTextLabel?.textColor = UIColor.white
if let profileImageUrl = user.profileImageUrl {
cell.profileImageView.loadImageUsingCacheWithUrlString(profileImageUrl)
} else {
tableView.deleteRows(at: [indexPath], with: .automatic)
tableView.reloadData()
}
}
return cell
}
这就是我所拥有的。如果电话号码不在通讯录中,它会删除用户行,但会留下白行。
【问题讨论】:
标签: ios swift uitableview