我的問題是當我滾動tableview它不能正常工作。TableView無法正常工作
例如我有2節和第0節我在單元格和第1節中使用配置文件圖像我隱藏了它們,但是當我向下滾動圖像失敗時。我也有一個變量,當它確定我正在改變第二個圖像。但是當我滾動其變化的圖像,但是當我向下滾動其更改與indexpath相同的圖像時。
你可以在這裏找到圖片
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! UserTableViewCell
if self.itemInfo.title == "USERNAME" && indexPath.section == 0 {
let user = self.users[indexPath.row]
let friendImage = UIImage(named: "SearchPeopleAdded")
for friend in self.friends {
if friend.objectId == user.objectId {
cell.groupAddImageView.image = friendImage
cell.selectionStyle = .None
cell.userInteractionEnabled = false
}
}
cell.nameLabel!.text = user["username"] as? String
if let image = user["avatar_image"] as? PFFile {
cell.userImageView.sd_setImageWithURL(NSURL(string: image.url!))
}
}else if itemInfo.title == "ADDRESSBOOK" && indexPath.section == 1 {
if isSearchActive == false {
let person = contacts[indexPath.row]
var firstName = person.name?.firstName
var lastName = person.name?.lastName
if firstName == nil || lastName == nil {
if firstName == nil {
firstName = ""
}
if lastName == nil {
lastName = ""
}
if firstName == nil && lastName == nil {
if person.phones![0].number != nil {
firstName = person.phones![0].number
lastName = ""
}else {
firstName = ""
lastName = ""
}
}
}
let fullName: String = firstName! + " " + lastName!
cell.nameLabel.text = fullName
cell.userImageView.hidden = true
}else {
let person = filteredAddressBookUsers[indexPath.row]
var firstName = person.name?.firstName
var lastName = person.name?.lastName
if firstName == nil || lastName == nil {
if firstName == nil {
firstName = ""
print("first name nil")
}
if lastName == nil {
lastName = ""
print("last name nil")
}
if firstName == nil && lastName == nil {
print("both nil")
if person.phones![0].number != nil {
firstName = person.phones![0].number
lastName = ""
}else {
firstName = ""
lastName = ""
}
}
}
let fullName: String = firstName! + " " + lastName!
cell.nameLabel.text = fullName
cell.userImageView.hidden = true
}
}else if self.itemInfo.title == "ADDRESSBOOK" && indexPath.section == 0 {
let user = self.addressMatchedUsers[indexPath.row]
let friendImage = UIImage(named: "SearchPeopleAdded")
for friend in self.friends {
if friend.objectId == user.objectId {
cell.groupAddImageView.image = friendImage
cell.selectionStyle = .None
cell.userInteractionEnabled = false
}
}
cell.nameLabel!.text = user["username"] as? String
if let image = user["avatar_image"] as? PFFile {
cell.userImageView.sd_setImageWithURL(NSURL(string: image.url!))
}
}
//configure(cell, forRowAtIndexPath: indexPath)
return cell
}
添加'cellForRowAtIndexPath'的整個代碼。 –
編輯問題 –
讓用戶= self.users [** indexPath.row **]在這裏,而不是indexPath.row你應該做indexPath.section,因爲你有分段tableView。 –