使用自定义单元格时出现奇怪的问题

时间:2014-09-03 08:27:34

标签: ios uitableview swift custom-cell

我正在尝试创建一个自定义表格视图单元格并在我的项目中使用它。不幸的是,我在委托方法cellForRowAtIndexPath中出现错误,我真的不明白为什么

人员班级

import Foundation
class Person {
 var name = "name"
 var imageName = "blank"

 init(name:String , image :String){
    self.name = name
    self.imageName = image
 }
}

自定义单元格类如下所示: 导入UIKit

class personTableViewCell: UITableViewCell {

 @IBOutlet var label: UILabel!
 @IBOutlet var iamge: UIImageView!

   override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)


}

required init(coder aDecoder: NSCoder) {
  super.init(coder: aDecoder)
}


override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
 }


}

我在这里使用它:

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecordRef!) {

    var arrayItems = ["firstName","lastName","mobileNumber","homeNumber","homeEmail","workEmail","address","city","zip","image"]
    var valuesArray = ["","","","","","","","","",""]
    var dictionary  :NSMutableDictionary =  NSMutableDictionary(objects: valuesArray, forKeys: arrayItems   )

    var firstName: NSString! = Unmanaged<CFString>.fromOpaque(ABRecordCopyValue(person, kABPersonFirstNameProperty).toOpaque()).takeUnretainedValue().__conversion()
    var lastName = Unmanaged<CFString>.fromOpaque(ABRecordCopyValue(person, kABPersonLastNameProperty).toOpaque()).takeRetainedValue().__conversion()

    dictionary.setObject(firstName, forKey: "firstName")
    if lastName == "" {

    }
    else{
        dictionary.setObject(lastName, forKey: "lastName")
    }

    //        println("\(firstName) \(lastName)")
    //     Unmanaged<CFString>.fromOpaque(ABRecordCopyValue(person, kABPersonPhoneProperty).toOpaque()).takeRetainedValue().__conversion()

    let unmanagedPhones = ABRecordCopyValue(person, kABPersonPhoneProperty)
    let phones: ABMultiValueRef =
    Unmanaged.fromOpaque(unmanagedPhones.toOpaque()).takeUnretainedValue()
        as NSObject as ABMultiValueRef

    let countOfPhones = ABMultiValueGetCount(phones)
    var ct2 = 1
    for index in 0..<countOfPhones{
        let unmanagedPhone = ABMultiValueCopyValueAtIndex(phones, index)

        let phone: String = Unmanaged.fromOpaque(
            unmanagedPhone.toOpaque()).takeUnretainedValue() as NSObject as String
        if ct2 == 1 {
            dictionary.setObject(phone, forKey: "mobileNumber")
            ct2 = ct2 + 1
        }
        else{
            dictionary.setObject(phone, forKey: "homeNumber")

        }

        // println(phone)

    }
    let unmanangedEmail = ABRecordCopyValue(person, kABPersonEmailProperty)
    let emails :ABMultiValueRef = Unmanaged.fromOpaque(unmanangedEmail.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef
    //var oneEmail = ABMultiValueCopyValueAtIndex(emails, 0)
    //var secEmail = ABMultiValueCopyValueAtIndex(emails, 1)
    //var email :String   = Unmanaged.fromOpaque(oneEmail.toOpaque()).takeUnretainedValue() as NSObject as String
    var workEmail :String = String()


    let countOfEmail = ABMultiValueGetCount(emails)
    var ct = 1
    for index2 in 0..<countOfEmail {
        var oneEmail = ABMultiValueCopyValueAtIndex(emails, index2)
        var email :String   = Unmanaged.fromOpaque(oneEmail.toOpaque()).takeUnretainedValue() as NSObject as String
        if ct==1 {
            dictionary.setObject(email ,forKey: "homeEmail")
            ct++
        }
        else {
            dictionary.setObject(email,forKey:"workEmail")
        }
        // print("\(email) is the email")
    }


    if ABPersonHasImageData(person) {
      //  var imageData  : CFDataRef = Unmanaged.fromOpaque(ABPersonCopyImageData(person).toOpaque()).takeUnretainedValue() as CFDataRef
      //  self.image = UIImage(data: imageData)
       // var contactImage :CFData = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail).takeRetainedValue()
      //  dictionary.setObject(imageData, forKey: "image")
    }

    //            dictionary.setObject(workEmail,forKey:"workEmail")

    var unamangedAddressDictionary = ABRecordCopyValue(person, kABPersonAddressProperty)
    let addresses : ABMultiValueRef = Unmanaged.fromOpaque(unamangedAddressDictionary.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef
    //  var addressDictionary : NSDictionary = Unmanaged.fromOpaque(ABMultiValueCopyValueAtIndex(unamangedAddressDictionary, 0).toOpaque())
    var addressDictionary  = ABMultiValueCopyValueAtIndex(addresses, 0).takeUnretainedValue()  as NSDictionary
    if addressDictionary.objectForKey(kABPersonAddressCityKey) == nil {

    }
    else{
        var smth: AnyObject? = addressDictionary.objectForKey(kABPersonAddressCityKey)
       // dictionary.setObject(addressDictionary.objectForKey(kABPersonAddressCityKey) , forKey: "city")

// dictionary.setObject(smth,forKey:“city”)

        dictionary.setValue(addressDictionary.objectForKey(kABPersonAddressCityKey), forKey: "city")

    }
    if addressDictionary.objectForKey(kABPersonAddressZIPKey) == nil {
    }
    else {
    //    dictionary.setObject(addressDictionary.objectForKey(kABPersonAddressZIPKey), forKey: "zip")
       dictionary.setValue(addressDictionary.objectForKey(kABPersonAddressZIPKey), forKey: "zip")

    }
    if addressDictionary.objectForKey(kABPersonAddressStreetKey) == nil {

    }
    else{

    //    dictionary.setObject(addressDictionary.objectForKey(kABPersonAddressStreetKey), forKey: "address")
        dictionary.setValue(addressDictionary.objectForKey(kABPersonAddressStreetKey), forKey: "address")

    }

    contactsArray.addObject(dictionary)
    //  println(contactsArray)
    var fullName = firstName + " " + lastName
    self.empty =  true
    var pers : Person = Person(name: fullName, image: "")
    self.arrayOfPerson.append(pers)
    self.objects.addObject(fullName)
    self.tableView?.reloadData()
    self.addressBookController.dismissViewControllerAnimated(true, completion: nil)
    //println("\(dictionary)")
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    let cell : personTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as personTableViewCell 
    self.ceva = "mere"
    // Configure the cell...
    //cell.textLabel.text = self.objects[indexPath.row] as NSString

    let person :Person = self.arrayOfPerson[indexPath.row] as Person
    cell.label.text = person.name
    if self.image != nil {
        cell.iamge.image = self.image
    }
    else {
        cell.iamge.image = UIImage(named: "nopicture.png")
    }
    return cell
}

使用标识符

将其取消时出错
  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:' - [UILabel isEqualToString:]:   无法识别的选择器发送到实例0x79e51190'

我正确设置了标识符,我从中获取该人的数组中包含了项目

你们能帮帮我,告诉我哪里做错了吗?

非常感谢任何类型的建议

0 个答案:

没有答案